clear all
set more off
set mem 10000000
set matsize 10000
version 13

************************************************************** 
*** Fuzzy Merge of Schools Data into Census Data *************
*** (to be run after "merge_habitation.do") ******************
************************************************************** 

** Set file paths
do "$path_code/paths.do"

********************************************************************************
********************************************************************************

** Step 1: Prep census data for merge with schools data
{
use "$pca/pca_census01_names.dta", clear
drop no_hh tot_p tot_m tot_f
joinby st_code dt_code vi_code using "$vd01/vd_2001_names.dta", unmatched(both)
drop _merge
joinby st_code dt_code vi_code using "$pca/pca_census11_names.dta", unmatched(both)
drop _merge
merge m:m st_code11 dt_code11 vi_code11 using "$vd11/vd_2011_all_raw.dta", nogen keepusing(village_vd11 bk* block*) keep(1 3)
merge m:m conc_id using "$conc/census_code_matches_names.dta", nogen ///
          keepusing(bk_code_conc01 village_conc01 bk_code_conc11 village_conc11 block_2001 block_2011)
merge m:1 pca01_id using "$panel/panel_dataset_no_lights.dta", nogen ///
          keepusing(vd11_id vd_edu_n_p_sch_?? vd_edu_n_m_sch_?? vd_edu_d_??) 
merge m:1 vd11_id using "$vd11/vd_2011.dta", keepusing(vill_pin_11) keep(1 3) nogen
gen names_id = _n
foreach v of varlist state district* block* village* {
	replace `v' = upper(trim(itrim(`v')))
}
duplicates drop
unique pca01_id
drop if st_code==.
compress
save "$smerge/names_for_merge.dta", replace

use "$smerge/names_for_merge.dta", clear
collapse (count) pca01_id, by(state st_code district dt_code district11 block bk_code_pca bk_code2_vd block11 block2_vd11) fast
compress
save "$smerge/names_for_merge_temp_blocks.dta", replace
}

********************************************************************************
********************************************************************************

** Step 2: Prep 2013 Schools data for fuzzy merge algorithm
{
use "$schools/school_village_codes_ALL_unique_new.dta", clear

  // standardize state names
replace state = subinstr(state,"&amp;","AND",.)
replace state = "JAMMU & KASHMIR" if state=="JAMMU AND KASHMIR" | state=="JAMMU &KASHMIR"
replace state = "CHHATTISGARH" if state=="CHATTISGARH"
replace state = "UTTARAKHAND" if state=="UTTRANCHAL" | state=="UTTARANCHAL"
replace state = "DADRA & NAGAR HAVELI" if state=="DADRA &NAGAR HAVELI"
replace state = "DAMAN & DIU" if state=="DAMAN &DIU"
drop if state=="DAMAN & DIU" | state=="DELHI" | state=="DADRA & NAGAR HAVELI" ///
  | state=="CHANDIGARH" | state=="ANDAMAN & NICOBAR ISLANDS" | state=="LAKSHADWEEP" ///
  | state=="GOA" | state=="PONDICHERRY"
replace state = upper(trim(itrim(state)))

  // drop obvious cities
drop if state=="ANDHRA PRADESH" & district=="HYDERABAD"
drop if state=="KARNATAKA" & district=="BANGALORE U NORTH"
drop if state=="KARNATAKA" & district=="BANGALORE U SOUTH"
drop if state=="KARNATAKA" & district=="BANGALORE SOUTH"
drop if state=="KARNATAKA" & district=="BANGALORE NORTH"
drop if state=="TAMIL NADU" & district=="CHENNAI"
drop if state=="WEST BENGAL" & district=="KOLKATA"
drop if state=="MAHARASHTRA" & district=="MUMBAI"
drop if state=="MAHARASHTRA" & district=="MUMBAI (SUBURBAN)"
drop if state=="MAHARASHTRA" & district=="MUMBAI II"

gen dt_code = real(substr(school_code,3,2))

****** UNCOMMENT TO DEBUG DISTRICT/BLOCK MATCHES
/*
keep st_code dt_code state district block
duplicates drop
*/
******

  // standardize district names
{
replace district = upper(trim(itrim(district)))
replace district = "KIPHIRE" if district=="KIPHERE" & state=="NAGALAND"
replace district = "NARSIMHAPUR" if district=="NARSINGHPUR" & state=="MADHYA PRADESH"
replace district = "SHAHDOL" if district=="ANUP PUR" & state=="MADHYA PRADESH"
replace district = "NORTH TRIPURA" if district=="NORTH" & state=="TRIPURA" 
replace district = "SOUTH TRIPURA" if district=="SOUTH" & state=="TRIPURA" 
replace district = "WEST TRIPURA" if district=="WEST" & state=="TRIPURA" 
replace district = "SANT RAVIDAS NAGAR BHADOHI" if district=="BHADOHI" & state=="UTTAR PRADESH"
replace district = "LOWER SUBANSIRI" if state=="ARUNACHAL PRADESH" & district=="KURUNG KUMEY"
replace district = "KAMRUP" if state=="ASSAM" & district=="KAMRUP-RURAL"
replace district = "NORTH CACHAR HILLS" if state=="ASSAM" & district=="DIMA HASAO"
replace district = "AURANGABAD" if state=="BIHAR" & district=="AURANGABAD (BIHAR)"
replace district = "RAIGARH" if state=="CHHATTISGARH" & district=="RAIGARH (CHHATTISGARH)"
replace district = "BILASPUR" if state=="CHHATTISGARH" & district=="BILASPUR (CHHATTISGARH)"
replace district = "BASTAR" if state=="CHHATTISGARH" & district=="BASTER"
replace district = "SURAT" if state=="GUJARAT" & district=="TAPI"
replace district = "BILASPUR" if state=="HIMACHAL PRADESH" & district=="BILASPUR (H.P.)"
replace district = "HAMIRPUR" if state=="HIMACHAL PRADESH" & district=="HAMIRPUR (H.P.)"
replace district = "LAHUL & SPITI" if state=="HIMACHAL PRADESH" & district=="LAHUL &AMP; SPITI"
replace district = "BARAMULA" if state=="JAMMU & KASHMIR" & district=="BANDIPORA"
replace district = "SRINAGAR" if state=="JAMMU & KASHMIR" & district=="GANDERBAL"
replace district = "SRINAGAR" if state=="JAMMU & KASHMIR" & district=="GANDERBAL"
replace district = "DODA" if state=="JAMMU & KASHMIR" & district=="KISHTWAR"
replace district = "ANANTNAG" if state=="JAMMU & KASHMIR" & district=="KULGAM"
replace district = "DODA" if state=="JAMMU & KASHMIR" & district=="RAMBAN"
replace district = "UDHAMPUR" if state=="JAMMU & KASHMIR" & district=="REASI"
replace district = "JAMMU" if state=="JAMMU & KASHMIR" & district=="SAMBA"
replace district = "PULWAMA" if state=="JAMMU & KASHMIR" & district=="SHOPIAN"
replace district = "BELGAUM" if state=="KARNATAKA" & district=="BELGAUM CHIKKODI"
replace district = "BELGAUM" if state=="KARNATAKA" & district=="CHIKKODI"
replace district = "CHAMARAJANAGAR" if state=="KARNATAKA" & district=="CHAMARAJANAGARA"
replace district = "CHAMARAJANAGAR" if state=="KARNATAKA" & district=="CHAMRAJNAGAR"
replace district = "DAVANAGERE" if state=="KARNATAKA" & district=="DAVANGERE"
replace district = "KOLAR" if state=="KARNATAKA" & district=="CHIKKABALLAPURA"
replace district = "CHIKMAGALUR" if state=="KARNATAKA" & district=="CHIKKAMANGALORE"
replace district = "BANGALORE RURAL" if state=="KARNATAKA" & district=="RAMANAGARA"
replace district = "TUMKUR" if state=="KARNATAKA" & district=="TUMKUR MADHUGIRI"
replace district = "TUMKUR" if state=="KARNATAKA" & district=="MADHUGIRI"
replace district = "GULBARGA" if state=="KARNATAKA" & district=="YADAGIRI"
replace district = "JHABUA" if state=="MADHYA PRADESH" & district=="ALIRAJPUR"
replace district = "SHAHDOL" if state=="MADHYA PRADESH" & district=="ANUPPUR"
replace district = "GUNA" if state=="MADHYA PRADESH" & district=="ASHOKNAGAR"
replace district = "GUNA" if state=="MADHYA PRADESH" & district=="ASHOK NAGAR"
replace district = "EAST NIMAR" if state=="MADHYA PRADESH" & district=="KHANDWA"
replace district = "EAST NIMAR" if state=="MADHYA PRADESH" & district=="KANDHWA"
replace district = "SIDHI" if state=="MADHYA PRADESH" & district=="SINGRAULI"
*replace district = "KANDHWA" if state=="MADHYA PRADESH" & district=="BURHANPUR"
replace district = "WEST NIMAR" if state=="MADHYA PRADESH" & district=="KHARGONE"
replace district = "AURANGABAD" if state=="MAHARASHTRA" & district=="AURANGABAD (MAHARASHTRA)"
replace district = "RAIGARH" if state=="MAHARASHTRA" & district=="RAIGARH (MAHARASHTRA)"
replace district = "MAYURBHANJ" if state=="ORISSA" & district=="MAYURBHANJA"
replace district = "NABARANGAPUR" if state=="ORISSA" & district=="NAWARANGAPUR"
replace district = "SENAPATI (EXCLUDING 3 SUB-DIVISIONS)" if state=="MANIPUR" & district=="SENAPATI"
replace district = "SANGRUR" if state=="PUNJAB" & district=="BARNALA"
replace district = "FIROZPUR" if state=="PUNJAB" & district=="FEROZEPUR"
replace district = "RUPNAGAR" if state=="PUNJAB" & district=="ROPAR"
replace district = "HAZARIBAGH" if state=="JHARKHAND" & district=="HAZARIBAG"
replace district = "HAZARIBAGH" if state=="JHARKHAND" & district=="JAMTARA"
replace district = "HAZARIBAGH" if state=="JHARKHAND" & district=="KHUNTI"
replace district = "HAZARIBAGH" if state=="JHARKHAND" & district=="LATEHAR"
replace district = "HAZARIBAGH" if state=="JHARKHAND" & district=="RAMGARH"
replace district = "HAZARIBAGH" if state=="JHARKHAND" & district=="SARAIKELA-KHARSAWAN"
replace district = "HAZARIBAGH" if state=="JHARKHAND" & district=="SIMDEGA"
replace district = "ANUGUL" if state=="ORISSA" & district=="ANGUL"
replace district = "BALESHWAR" if state=="ORISSA" & district=="BALASORE"
replace district = "BALANGIR" if state=="ORISSA" & district=="BOLANGIR"
replace district = "BAUDH" if state=="ORISSA" & district=="BOUDH"
replace district = "ANUGUL" if state=="ORISSA" & district=="DEOGARH"
replace district = "JAGATSINGHAPUR" if state=="ORISSA" & district=="JAGATSINGHPUR"
replace district = "JAJAPUR" if state=="ORISSA" & district=="JAJPUR"
replace district = "KENDUJHAR" if state=="ORISSA" & district=="KEONJHAR"
replace district = "NABARANGAPUR" if state=="ORISSA" & district=="NABARANGPUR"
replace district = "SONAPUR" if state=="ORISSA" & district=="SONEPUR"
replace district = "SUNDARGARH" if state=="ORISSA" & district=="SUNDERGARH"
replace district = "AMRITSAR" if state=="PUNJAB" & district=="TARAN TARAN"
replace district = "CHITTAURGARH" if state=="RAJASTHAN" & district=="CHITTORGARH"
replace district = "PRATAPGARH" if state=="RAJASTHAN" & district=="PRATAPGARH(RAJ.)"
replace district = "PRATAPGARH" if state=="RAJASTHAN" & district=="PRATAPGARH (RAJ.)"
replace district = "GARHWAL" if state=="UTTARAKHAND" & district=="PAURI GARHWAL"
    // DEAL WITH PRATAPGARH (RAJ.) -- duplicate 3x
expand 3 if state=="RAJASTHAN" & district=="PRATAPGARH"
expand 2 if state=="PUNJAB" & district=="MOHALI"
bysort state district block /*village school_code*/: gen counter = _n
replace counter = 1 if counter==4
replace counter = 2 if counter==5
replace counter = 3 if counter==6
replace counter = 1 if counter==7
replace counter = 2 if counter==8
replace counter = 3 if counter==9
replace counter = 1 if counter==10
replace counter = 2 if counter==11
replace counter = 3 if counter==12
replace district = "CHITTAURGARH" if counter ==1 & state=="RAJASTHAN" & district=="PRATAPGARH"
replace district = "UDAIPUR" if counter ==2 & state=="RAJASTHAN" & district=="PRATAPGARH"
replace district = "BANSWARA" if counter ==3 & state=="RAJASTHAN" & district=="PRATAPGARH"
replace district = "RUPNAGAR" if counter ==1 & state=="PUNJAB" & district=="MOHALI"
replace district = "PATIALA" if counter ==2 & state=="PUNJAB" & district=="MOHALI"
drop counter 
replace district = "FARIDABAD" if state=="HARYANA" & district=="MEWAT"
replace district = "TUENSANG" if state=="NAGALAND" & district=="LONGLENG"
replace district = "EAST" if state=="SIKKIM" & district=="EAST SIKKIM"
replace district = "NORTH" if state=="SIKKIM" & district=="NORTH SIKKIM"
replace district = "SOUTH" if state=="SIKKIM" & district=="SOUTH SIKKIM"
replace district = "WEST" if state=="SIKKIM" & district=="WEST SIKKIM"
replace district = "DHARMAPURI" if state=="TAMIL NADU" & district=="KRISHANAGIRI"
replace district = "SANT RAVIDAS NAGAR BHADOHI" if state=="UTTAR PRADESH" & district=="BHADOI"
replace district = "BULANDSHAHAR" if state=="UTTAR PRADESH" & district=="BULANDSHAHR"
replace district = "HAMIRPUR" if state=="UTTAR PRADESH" & district=="HAMIRPUR (U.P.)"
replace district = "MAHRAJGANJ" if state=="UTTAR PRADESH" & district=="MAHARAJGANJ"
replace district = "NORTH TWENTY FOUR PARGANAS" if state=="WEST BENGAL" & district=="NORTH TWENTY FOUR PARGANA"
replace district = "MEDINIPUR" if state=="WEST BENGAL" & district=="PASCHIM MEDINIPUR"
replace district = "MEDINIPUR" if state=="WEST BENGAL" & district=="PURBA MEDINIPUR"
replace district = "DARJILING" if state=="WEST BENGAL" & district=="SILIGURI"
replace district = "SOUTH TWENTY FOUR PARGANAS" if state=="WEST BENGAL" & district=="SOUTH TWENTY FOUR PARGAN"
replace district = "AHMADABAD" if state=="GUJARAT" & district=="AHMEDABAD"
replace district = "MARIGAON" if state=="ASSAM" & district=="MORIGAON"
replace district = "UTTARA KANNADA" if state=="KARNATAKA" & district=="UTTARA KANNADA SIRSI"

replace district = "CUDDAPAH" if state=="ANDHRA PRADESH" & district=="KADAPA"
replace district = "DARRANG" if state=="ASSAM" & district=="UDALGURI" & dt_code==26
replace dt_code = 8 if state=="ASSAM" & district=="DARRANG" & dt_code==26
replace district = "SHAJAPUR" if state=="MADHYA PRADESH" & district=="AGAR MALWA" & dt_code==51
replace dt_code = 22 if state=="MADHYA PRADESH" & district=="SHAJAPUR" & dt_code==51
replace district = "THANE" if state=="MAHARASHTRA" & district=="PALGHAR" & dt_code==36
replace dt_code = 21 if state=="MAHARASHTRA" & district=="THANE" & dt_code==36
replace district = "DEBAGARH" if state=="ORISSA" & district=="ANUGUL" & dt_code==4
replace dt_code = 15 if state=="ORISSA" & district=="ANUGUL" & dt_code==4
replace district = "FIROZPUR" if state=="PUNJAB" & district=="FAZILKA" & dt_code==21
replace dt_code = 11 if state=="PUNJAB" & district=="FIROZPUR" & dt_code==21
replace district = "ETAH" if state=="UTTAR PRADESH" & district=="KANSHIRAM NAGAR" & dt_code==72
replace district = "ETAH" if state=="UTTAR PRADESH" & district=="KASHIRAM NAGAR" & dt_code==72
replace dt_code = 17 if state=="UTTAR PRADESH" & district=="ETAH" & dt_code==72
replace dt_code = 68 if state=="UTTAR PRADESH" & district=="SANT RAVIDAS NAGAR BHADOHI" & dt_code==71
replace district = "JALPAIGURI" if state=="WEST BENGAL" & district=="ALIPURDUAR" & dt_code==22
replace dt_code = 2 if state=="WEST BENGAL" & district=="JALPAIGURI" & dt_code==22
replace dt_code = 15 if state=="WEST BENGAL" & district=="MEDINIPUR"
replace district = "EAST GARO HILLS" if state=="MEGHALAYA" & district=="NORTH GARO HILLS" & dt_code==8
replace dt_code = 2 if state=="MEGHALAYA" & district=="EAST GARO HILLS" & dt_code==8
replace district = "WEST GARO HILLS" if state=="MEGHALAYA" & district=="SOUTH WEST GARO HILLS" & dt_code==11
replace dt_code = 1 if state=="MEGHALAYA" & district=="WEST GARO HILLS" & dt_code==11
replace district = "WEST KHASI HILLS" if state=="MEGHALAYA" & district=="SOUTH WEST KHASI HILLS" & dt_code==10
replace dt_code = 4 if state=="MEGHALAYA" & district=="WEST KHASI HILLS" & dt_code==10
replace district = "JAINTIA HILLS" if state=="MEGHALAYA" & district=="EAST JAINTIA HILLS" & dt_code==9
replace dt_code = 7 if state=="MEGHALAYA" & district=="JAINTIA HILLS" & dt_code==9
replace district = "LOHIT" if state=="ARUNACHAL PRADESH" & district=="ANJAW" & dt_code==16
replace dt_code = 11 if state=="ARUNACHAL PRADESH" & district=="LOHIT" & dt_code==16
replace district = "LOWER SUBANSIRI" if state=="ARUNACHAL PRADESH" & district=="KRA DADI" & dt_code==19
replace dt_code = 5 if state=="ARUNACHAL PRADESH" & district=="LOWER SUBANSIRI" & dt_code==19
replace district = "TIRAP" if state=="ARUNACHAL PRADESH" & district=="LONGDING" & dt_code==17
replace dt_code = 13 if state=="ARUNACHAL PRADESH" & district=="TIRAP" & dt_code==17
replace district = "DIBANG VALLEY" if state=="ARUNACHAL PRADESH" & district=="LOWER DIBANG VALLEY" & dt_code==15
replace dt_code = 10 if state=="ARUNACHAL PRADESH" & district=="DIBANG VALLEY" & dt_code==15
replace district = "LOHIT" if state=="ARUNACHAL PRADESH" & district=="NAMSAI" & dt_code==18
replace dt_code = 11 if state=="ARUNACHAL PRADESH" & district=="LOHIT" & dt_code==18
replace district = "DURG" if state=="CHHATTISGARH" & district=="BALOD" & dt_code==22
replace dt_code = 10 if state=="CHHATTISGARH" & district=="DURG" & dt_code==22
replace district = "RAIPUR" if state=="CHHATTISGARH" & district=="BALODABAZAR" & dt_code==24
replace dt_code = 11 if state=="CHHATTISGARH" & district=="RAIPUR" & dt_code==24
replace district = "RAIPUR" if state=="CHHATTISGARH" & district=="GARIABAND" & dt_code==25
replace dt_code = 25 if state=="CHHATTISGARH" & district=="RAIPUR" & dt_code==24
replace district = "SURGUJA" if state=="CHHATTISGARH" & district=="BALRAMPUR" & dt_code==26
replace dt_code = 2 if state=="CHHATTISGARH" & district=="SURGUJA" & dt_code==26
replace district = "BILASPUR" if state=="CHHATTISGARH" & district=="MUNGELI" & dt_code==19
replace dt_code = 7 if state=="CHHATTISGARH" & district=="MUNGELI" & dt_code==19
replace district = "BASTAR" if state=="CHHATTISGARH" & district=="KONDAGAON" & dt_code==17
replace dt_code = 15 if state=="CHHATTISGARH" & district=="BASTAR" & dt_code==17
replace district = "BASTAR" if state=="CHHATTISGARH" & district=="NARAYANPUR" & dt_code==18
replace dt_code = 15 if state=="CHHATTISGARH" & district=="BASTAR" & dt_code==18
replace district = "BASTAR" if state=="CHHATTISGARH" & district=="SUKMA" & dt_code==21
replace dt_code = 16 if state=="CHHATTISGARH" & district=="DANTEWADA" & dt_code==21
replace district = "DANTEWADA" if state=="CHHATTISGARH" & district=="BIJAPUR" & dt_code==20
replace dt_code = 16 if state=="CHHATTISGARH" & district=="DANTEWADA" & dt_code==20
replace district = "SURGUJA" if state=="CHHATTISGARH" & district=="SURAJPUR" & dt_code==27
replace dt_code = 2 if state=="CHHATTISGARH" & district=="SURGUJA" & dt_code==27
replace district = "DURG" if state=="CHHATTISGARH" & district=="BEMETARA" & dt_code==23
replace dt_code = 10 if state=="CHHATTISGARH" & district=="DURG" & dt_code==23
replace district = "SABAR KANTHA" if state=="GUJARAT" & district=="ARAVALLI" & dt_code==27
replace dt_code = 5 if state=="GUJARAT" & district=="ARAVALLI" & dt_code==27
replace district = "VADODARA" if state=="GUJARAT" & district=="CHHOTAUDEPUR" & dt_code==32
replace dt_code = 19 if state=="GUJARAT" & district=="VADODARA" & dt_code==32
replace district = "JAMNAGAR" if state=="GUJARAT" & district=="DEVBHOOMI DWARKA" & dt_code==29
replace dt_code = 10 if state=="GUJARAT" & district=="JAMNAGAR" & dt_code==29
replace district = "JUNAGADH" if state=="GUJARAT" & district=="GIR SOMNATH" & dt_code==30
replace dt_code = 12 if state=="GUJARAT" & district=="JUNAGADH" & dt_code==30
replace district = "GHAZIABAD" if state=="UTTAR PRADESH" & district=="HAPUR (PANCHSHEEL NAGAR)" & dt_code==75
replace dt_code = 9 if state=="UTTAR PRADESH" & district=="GHAZIABAD" & dt_code==75
replace district = "MORADABAD" if state=="UTTAR PRADESH" & district=="SAMBHAL (BHIM NAGAR)" & dt_code==68
replace dt_code = 4 if state=="UTTAR PRADESH" & district=="MORADABAD" & dt_code==68
replace district = "MUZAFFARNAGAR" if state=="UTTAR PRADESH" & district=="SHAMLI (PRABUDH NAGAR)" & dt_code==74
replace dt_code = 2 if state=="UTTAR PRADESH" & district=="MUZAFFARNAGAR" & dt_code==74
replace district = "JEHANABAD" if state=="BIHAR" & district=="ARWAL" & dt_code==38
replace dt_code = 33 if state=="BIHAR" & district=="JEHANABAD" & dt_code==38
replace district = "SOUTH TRIPURA" if state=="TRIPURA" & district=="GOMATI" & dt_code==7
replace dt_code = 2 if state=="TRIPURA" & district=="SOUTH TRIPURA" & dt_code==7
replace district = "WEST TRIPURA" if state=="TRIPURA" & district=="KHOWAI" & dt_code==6
replace dt_code = 1 if state=="TRIPURA" & district=="WEST TRIPURA" & dt_code==6
replace district = "WEST TRIPURA" if state=="TRIPURA" & district=="SEPAHIJALA" & dt_code==5
replace dt_code = 1 if state=="TRIPURA" & district=="WEST TRIPURA" & dt_code==5
replace district = "NORTH TRIPURA" if state=="TRIPURA" & district=="UNAKOTI" & dt_code==8
replace dt_code = 4 if state=="TRIPURA" & district=="NORTH TRIPURA" & dt_code==8
replace district = "GURDASPUR" if state=="PUNJAB" & district=="PATHANKOT" & dt_code==22
replace dt_code = 1 if state=="PUNJAB" & district=="GURDASPUR" & dt_code==22
replace district = "FARIDABAD" if state=="HARYANA" & district=="PALWAL" & dt_code==21
replace dt_code = 19 if state=="HARYANA" & district=="FARIDABAD" & dt_code==21
replace district = "TUENSANG" if state=="NAGALAND" & district=="KIPHIRE" & dt_code==9
replace dt_code = 2 if state=="NAGALAND" & district=="TUENSANG" & dt_code==9
replace district = "TUENSANG" if state=="NAGALAND" & district=="KIPHIRE" & dt_code==10
replace dt_code = 2 if state=="NAGALAND" & district=="TUENSANG" & dt_code==10
replace district = "KOHIMA" if state=="NAGALAND" & district=="PEREN" & dt_code==11
replace dt_code = 7 if state=="NAGALAND" & district=="KOHIMA" & dt_code==11
replace district = "EAST NIMAR" if state=="MADHYA PRADESH" & district=="BURHANPUR" & dt_code==48
replace dt_code = 29 if state=="MADHYA PRADESH" & district=="EAST NIMAR" & dt_code==48

}

 	// standardize block names
{
replace block = upper(trim(itrim(block)))
replace block = subinstr(subinstr(subinstr(block,"*","",.)," -"," ",.),"- "," ",.)
replace block = subinstr(subinstr(subinstr(subinstr(block,"( ","(",.)," )",")",.),"-I"," I",.),"-1"," I",.)
replace block = subinstr(subinstr(subinstr(block,"(T)","",.),"(S.T)","",.),"(M)","",.)
replace block = subinstr(subinstr(subinstr(subinstr(block,"C.D. BLOCK","",.),"C.D.BLOCK","",.),"SUB-DIV.","",.),"SUB-DIVISION","",.)
replace block = subinstr(subinstr(subinstr(subinstr(block,"T.D. BLOCK","",.),"T.D.BLOCK","",.),"T. D. BLOCK","",.),"_"," ",.)
replace block = trim(itrim(subinstr(subinstr(subinstr(block,"(P)","",.),"CIRCLE","",.),"BLOCK","",.)))
replace block = "BELLAMPALLE" if block=="BELLAMPALLY" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "DAHEGAON" if block=="DAHEGOAN" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "DANDEPALLE" if block=="DANDEPALLY" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "INDERAVELLY" if block=="INDERVELLY" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "KOTAPALLE" if block=="KOTAPALLY" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "KOUTHALA" if block=="KOUTALA" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "MANDAMARRI" if block=="MANDAMARRY" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "REBBANA" if block=="REBBENA" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "SIRPUR (T)" if block=="SIRPUR (U)" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "TIRYANI" if block=="THIRYANI" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "VEMANPALLE" if block=="VEMANPALLY" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "WANKDI" if block=="WANKIDI" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "BUKKARAYA SAMUDRAM" if block=="BUKKARAYASAMUDRAM" & district=="ANANTAPUR" & state=="ANDHRA PRADESH"
replace block = "GUMMAGATTA" if block=="GUMMAGATA" & district=="ANANTAPUR" & state=="ANDHRA PRADESH"
replace block = "KALYANDURG" if block=="KALYANDRUG" & district=="ANANTAPUR" & state=="ANDHRA PRADESH"
replace block = "NAMBULIPULIKUNTA" if block=="NAMBULAPULIKUNTA" & district=="ANANTAPUR" & state=="ANDHRA PRADESH"
replace block = "GANGADHARA NELLORE" if block=="GANGADHARANELLORE" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "NARAYANAVANAM" if block=="NARAYANAVARAM" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "PEDDA THIPPASAMUDRAM" if block=="PEDDATHIPPA SAMUDRAM" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "PENUMURU" if block=="PENUMUR" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "PILERU" if block=="PILER" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "SATYAVEDU" if block=="SATHYAVEDU" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "THAMBALLAPALLE" if block=="THAMBLLAPALLE" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "VADAMALAPETA" if block=="VADAMALAPET" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "YADAMARRI" if block=="YADAMARI" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "CHAPAD" if block=="CHAPADU" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "OBULAVARIPALLE" if block=="OBULAVARIPALLI" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "PENDLIMARRI" if block=="PENDLIMARRY" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "PRODDATUR" if block=="PRODDUTUR" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "PULLAMPETA" if block=="PULLAMPET" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "RAYACHOTI" if block=="RAYACHOTY" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "SAMBEPALLE" if block=="SAMBEPALLI" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "T SUNDUPALLE" if block=="T SUNDUPALLI" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "VEERABALLE" if block=="VEERABALLI" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "VEMPALLE" if block=="VEMPALLI" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "ANAPARTHY" if block=="ANAPARTHI" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "GANDEPALLE" if block=="GANDEPALLI" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "I. POLAVARAM" if block=="I.POLAVARAM" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "KOTHAPALLE" if block=="KOTHAPALLI" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "PRATHIPADU" if block=="PRATIPADU" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "RAJAHMUNDRY RURAL" if block=="RAJAHMUNDRY(RURAL)" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "SAKHINETIPALLE" if block=="SAKHINETIPALLI" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "SANKHAVARAM" if block=="SANKAVARAM" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "Y. RAMAVARAM" if block=="Y.RAMAVARAM" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "AMRUTHALUR" if block=="AMRUTHALURU" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "BHATTIPROLU" if block=="BATTIPROLU" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "KOLLUR" if block=="KOLLURU" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "NARASARAOPET" if block=="NARASARAOPETA" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "PONNUR" if block=="PONNURU" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "TADEPALLE" if block=="THADEPALLE" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "BHEEMADEVARPALLE" if block=="BHEEMADEVARAPALLI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "BOINPALLE" if block=="BOINPALLI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "CHANDURTHI" if block=="CHENDURTHI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "GOLLAPALLE" if block=="GOLLAPALLI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "JULAPALLE" if block=="JULAPALLI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "KAMALAPUR" if block=="KAMALAPOOR" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "KAMANPUR" if block=="KAMANPOOR" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "KODIMIAL" if block=="KODIMYAL" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "KONARAOPETA" if block=="KONARAOPET" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "MAHADEVPUR" if block=="MAHADEVPOOR" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "MALLAPUR" if block=="MALLAPOOR" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "METPALLE" if block=="METPALLI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "MUSTABAD" if block=="MUSTHABAD" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "PEGADAPALLE" if block=="PEGADAPALLI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "SAIDAPUR" if block=="SAIDAPOOR" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "SARANGAPUR" if block=="SARANGAPOOR" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "SIRCILLA" if block=="SIRICILLA" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "SRIRAMPUR" if block=="SRIRAMPOOR" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "SULTANABAD" if block=="SULTHANABAD" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "CHINTHAKANI" if block=="CHINTAKANI" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "JULURPAD" if block=="JULURPADU" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "KAMEPALLE" if block=="KAMEPALLY" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "MULKALAPALLE" if block=="MULAKALAPALLY" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "NELAKONDAPALLE" if block=="NELAKONDAPALLY" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "PALWANCHA" if block=="PALVONCHA" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "SATHUPALLE" if block=="SATHUPALLY" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "TEKULAPALLE" if block=="TEKULAPALLY" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "WAZEED" if block=="WAZEEDU" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "AGIRIPALLE" if block=="AGIRIPALLI" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "CHALLAPALLE" if block=="CHALLAPALLI" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "JAGGAYYAPETA" if block=="JAGGAYYAPET" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "KAIKALUR" if block=="KAIKALURU" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "MUDINEPALLE" if block=="MUDIENEPALLI" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "MUDINEPALLE" if block=="MUDINEPALLI" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "PEDAPARUPUDI" if block=="PEDAPARAPUDI" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "VEERULLAPADU" if block=="VERULLAPADU" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "VIJAYAWADA (RURAL)" if block=="VIJAYAWADA RURAL" & district=="KRISHNA" & state=="ANDHRA PRADESH"
replace block = "BANAGANAPALLE" if block=="BANAGANAPALLI" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "BANDI ATMAKUR" if block=="BANDIATMAKUR" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "KOILKUNTLA" if block=="KOILAKUNTLA" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "KOTHAPALLE" if block=="KOTAPALLI" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "PAGIDYALA" if block=="PAGIDALA" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "PATTIKONDA" if block=="PATHIKONDA" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "PEAPALLY" if block=="PEAPULLY" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "PEDDA KADUBUR" if block=="PEDDAKADUBUR" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "VELDURTHI" if block=="VELDURTI" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "VELGODE" if block=="VELUGODU" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "AMRABAD" if block=="AMARABAD" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "DAMARAGIDDA" if block=="DAMARGIDDA" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "DEVARKADRA" if block=="DEVARAKADRA" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "DHARUR" if block=="DHAROOR" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "DOULATHABAD" if block=="DOULTABAD" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "GHATTU" if block=="GATTU" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "GOPALPETA" if block=="GOPALPET" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "IEEJ" if block=="IEEJA" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "MAHBUBNAGAR" if block=="MAHABUBNAGAR" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "NARVA" if block=="NARWA" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "PEDDAKOTHAPALLE" if block=="PEDDAKOTHAPALLY" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "TALAKONDAPALLE" if block=="TALKONDAPALLY" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "TELKAPALLE" if block=="TELKAPALLY" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "WADDEPALLE" if block=="WADDEPALLY" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "DOULTABAD" if block=="DOULTHABAD" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "JAGDEVPUR" if block=="JAGADEVPUR" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "KOHIR" if block=="KOHEER" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "KONDAPUR" if block=="KONDAPOOR" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "KOWDIPALLE" if block=="KOWDIPALLY" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "MANOOR" if block=="MANOOOR" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "MULUG" if block=="MULUGU" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "MUNPALLE" if block=="MUNIPALLY" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "NANGNOOR" if block=="NANGANOOR" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "NARAYANKHED" if block=="NARAYANAKHED" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "PAPANNAPET" if block=="PAPANNAPPET" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "RAMACHANDRAPURAM" if block=="RAMACHANDRAPUR" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "SADASIVPET" if block=="SADASIVAPET" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "SHANKARAMPET (R)" if block=="SHANKARAMPET(A)" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "TUPRAN" if block=="TOOPRAN" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "ZAHIRABAD" if block=="ZAHEERABAD" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "BOMMALARAMARAM" if block=="BOMMALA RAMARAM" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "CHANDAM PET" if block=="CHANDAMPET" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "CHILKUR" if block=="CHILUKUR" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "CHINTHA PALLE" if block=="CHINTHAPALLE" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "DAMERACHERLA" if block=="DAMARACHERLA" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "GARIDE PALLE" if block=="GARIDEPALLY" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "GUNDLA PALLE" if block=="GUNDLAPALLE" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "HUZURNAGAR" if block=="HUZUR NAGAR" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "JAJI REDDI GUDEM" if block=="JAJI REDDY GUDEM" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "KANGAL" if block=="KANAGAL" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "KETHE PALLE" if block=="KETHEPALLE" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "M.TURKAPALLE" if block=="M TURKAPALLE" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "MATTAM PALLE" if block=="MATTAMPALLE" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "MELLA CHERUVU" if block=="MELLACHERUVU" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "MOTHEY" if block=="MOTHE" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "NAMPALLE" if block=="NAMPALLY" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "NARKETPALLE" if block=="NARKATPALLE" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "NEREDCHERLA" if block=="NEREDUCHERLA" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "NUTHANKAL" if block=="NUTANKAL" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "RAMANNAPETA" if block=="RAMANNAPET" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "SALI GOURARAM" if block=="SALIGOURARAM" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "THIPPARTHI" if block=="THIPPARTHY" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "THIRUMALGIRI" if block=="THIRUMALAGIRI" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "ANUMASAMUDRAMPETA" if block=="ANUMASAMUDRAMPET" & district=="NELLORE" & state=="ANDHRA PRADESH"
replace block = "ATMAKUR" if block=="ATHMAKUR" & district=="NELLORE" & state=="ANDHRA PRADESH"
replace block = "BALAYAPALLE" if block=="BALAYAPALLI" & district=="NELLORE" & state=="ANDHRA PRADESH"
replace block = "OJILI" if block=="OZILI" & district=="NELLORE" & state=="ANDHRA PRADESH"
replace block = "SULLURPETA" if block=="SULLURPET" & district=="NELLORE" & state=="ANDHRA PRADESH"
replace block = "ARMUR" if block=="ARMOOR" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "BIRKOOR" if block=="BIRKUR" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "DHARPALLE" if block=="DHARPALLY" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "DICHPALLE" if block=="DICHPALLY" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "JAKRANPALLE" if block=="JAKRANPALLY" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "KAMMARPALLE" if block=="KAMMARPALLY" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "KOTGIRI" if block=="KOTAGIRI" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "MORTAD" if block=="MORTHAD" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "NAGAREDDIPET" if block=="NAGIREDDYPET" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "RANJAL" if block=="RENJAL" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "SADASIVANAGAR" if block=="SADASHIVNAGAR" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "SIRKONDA" if block=="SIRIKONDA" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "YEDPALLE" if block=="YEDPALLY" & district=="NIZAMABAD" & state=="ANDHRA PRADESH"
replace block = "BESTAWARIPETA" if block=="BESTAVARIPETA" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "CHINAGANJAM" if block=="CHINAGANGAM" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "GIDDALUR" if block=="GIDDALURU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "HANUMANTHUNI PADU" if block=="HANUMANTHUNIPADU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "KANDUKUR" if block=="KANDUKURU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "KOTHA PATNAM" if block=="KOTHAPATNAM" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "MARTUR" if block=="MARTURU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "NAGULUPPALA PADU" if block=="NAGULUPPALAPADU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "PAMUR" if block=="PAMURU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "PARCHUR" if block=="PARCHURU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "RACHERLA" if block=="RACHARLA" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "SANTHANUTHALA PADU" if block=="SANTHANUTHALAPADU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "THALLUR" if block=="TALLURU" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "VOLETIVARIPALEM" if block=="VALETIVARIPALEM" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "YEDDANA PUDI" if block=="YEDDANAPUDI" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "ZARUGUMILLI" if block=="ZARUGUMALLI" & district=="PRAKASAM" & state=="ANDHRA PRADESH"
replace block = "IBRAHIMPATNAM" if block=="IBRHIMPATNAM" & district=="RANGAREDDI" & state=="ANDHRA PRADESH"
replace block = "MOINABAD" if block=="MOINBAD" & district=="RANGAREDDI" & state=="ANDHRA PRADESH"
replace block = "QUTUBULLAPUR" if block=="QUTHBULLAPUR" & district=="RANGAREDDI" & state=="ANDHRA PRADESH"
replace block = "VICARABAD" if block=="VIKARABAD" & district=="RANGAREDDI" & state=="ANDHRA PRADESH"
replace block = "ICHCHAPURAM" if block=="ICHAPURAM" & district=="SRIKAKULAM" & state=="ANDHRA PRADESH"
replace block = "KOTHURU" if block=="KOTTURU" & district=="SRIKAKULAM" & state=="ANDHRA PRADESH"
replace block = "RANASTALAM" if block=="RANASTHALAM" & district=="SRIKAKULAM" & state=="ANDHRA PRADESH"
replace block = "VAJRAPUKOTHURU" if block=="VAJRAPUKOTTURU" & district=="SRIKAKULAM" & state=="ANDHRA PRADESH"
replace block = "VEERAGHATTAM" if block=="VEERAAGHATTAM" & district=="SRIKAKULAM" & state=="ANDHRA PRADESH"
replace block = "ANAKAPALLE" if block=="ANAKAPALLI" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "ARAKU VALLEY" if block=="ARAKUVALLEY" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "CHINTAPALLE" if block=="CHINTAPALLI" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "DEVARAPALLE" if block=="DEVARAPALLI" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "NAKKAPALLE" if block=="NAKKAPALLI" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "NARSIPATNAM" if block=="NARASIPATNAM" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "PARAVADA" if block=="PARAWADA" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "PEDA BAYALU" if block=="PEDABAYALU" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "PEDAGANTYADA" if block=="PEDAGANTAYADA" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "PENDURTHI" if block=="PENDURTHY" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "YELAMANCHILI" if block=="YELLAMANCHILI" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "BONDAPALLE" if block=="BONDAPALLI" & district=="VIZIANAGARAM" & state=="ANDHRA PRADESH"
replace block = "CHEEPURUPALLE" if block=="CHEEPURUPALLI" & district=="VIZIANAGARAM" & state=="ANDHRA PRADESH"
replace block = "DATTIRAJERU" if block=="DATHIRAJERU" & district=="VIZIANAGARAM" & state=="ANDHRA PRADESH"
replace block = "KURUPAM" if block=="KURAPAM" & district=="VIZIANAGARAM" & state=="ANDHRA PRADESH"
replace block = "LAKKAVARAPUKOTA" if block=="LAKAVARAPUKOTA" & district=="VIZIANAGARAM" & state=="ANDHRA PRADESH"
replace block = "SALUR" if block=="SALURU" & district=="VIZIANAGARAM" & state=="ANDHRA PRADESH"
replace block = "KOTHAGUDEM" if block=="KOTHAGUDA" & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "LINGALAGHANPUR" if block=="LINGAL GHANPUR" & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "MOGULLAPALLE" if block=="MOGULLAPELLY" & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "PALAKURTHI" if block=="PALAKURTHY" & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "RAGHUNATHPALLE" if block=="RAGHUNATHPALLY" & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "TADVAI" if block=="THADVAI" & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "WARDHANNA PET" if block=="WARDHANNAPET" & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "AKIVIDU" if block=="AKIVEEDU" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "BUTTAYAGUDEM" if block=="BUTTAIGUDEM" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "DEVARAPALLE" if block=="DEVARAPALLI" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "JANGAREDDIGUDEM" if block=="JANGAREDDYGUDEM" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "JEELUGU MILLI" if block=="JEELUGUMILLI" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "MOGALTHUR" if block=="MOGALTUR" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "NARASAPURAM" if block=="NARSAPURAM" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "PALACODERU" if block=="PALAKODERU" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "T.NARASAPURAM" if block=="T.NARSAPURAM" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "TADEPALLIGUDEM" if block=="TADEPALLI GUDEM" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "DIYUN" if block=="DAYUN" & district=="CHANGLANG" & state=="ARUNACHAL PRADESH"
replace block = "KHIMIYONG" if block=="KHIMYANG" & district=="CHANGLANG" & state=="ARUNACHAL PRADESH"
replace block = "CHAYANGTAJO" if block=="CHAYANG TAJO" & district=="EAST KAMENG" & state=="ARUNACHAL PRADESH"
replace block = "CHOWKHAM" if block=="CHONGKHAM" & district=="LOHIT" & state=="ARUNACHAL PRADESH"
replace block = "PARSI-PARLO" if block=="PARSIPARLO" & district=="LOWER SUBANSIRI" & state=="ARUNACHAL PRADESH"
replace block = "LAJU" if block=="LAZU" & district=="TIRAP" & state=="ARUNACHAL PRADESH"
replace block = "LIMEKING" if block=="LIME KING" & district=="UPPER SUBANSIRI" & state=="ARUNACHAL PRADESH"
replace block = "PUCHI GEKO" if block=="PUCHIGEKO" & district=="UPPER SUBANSIRI" & state=="ARUNACHAL PRADESH"
replace block = "MECHUKA" if block=="MECHUKHA" & district=="WEST SIANG" & state=="ARUNACHAL PRADESH"
replace block = "MONIGONG" if block=="MONIGOAN" & district=="WEST SIANG" & state=="ARUNACHAL PRADESH"
replace block = "KATIGORA" if block=="KATIGORAH" & district=="CACHAR" & state=="ASSAM"
replace block = "UDARBOND" if block=="UDHARBOND" & district=="CACHAR" & state=="ASSAM"
replace block = "AGAMONI" if block=="AGOMONI" & district=="DHUBRI" & state=="ASSAM"
replace block = "GOLOKGANJ" if block=="GOLAKGANJ" & district=="DHUBRI" & state=="ASSAM"
replace block = "DUDHNAI" if block=="DUDHNOI" & district=="GOALPARA" & state=="ASSAM"
replace block = "KATLICHARA" if block=="KATLICHERRA" & district=="HAILAKANDI" & state=="ASSAM"
replace block = "PATHARKANDI" if block=="PATHER KANDI" & district=="KARIMGANJ" & state=="ASSAM"
replace block = "DOTOMA" if block=="DOTMA" & district=="KOKRAJHAR" & state=="ASSAM"
replace block = "MAIBONG" if block=="MAIBANG" & district=="NORTH CACHAR HILLS" & state=="ASSAM"
replace block = "DIMOW" if block=="DEMOW" & district=="SIBSAGAR" & state=="ASSAM"
replace block = "CHARIDUAR" if block=="CHAIDUAR" & district=="SONITPUR" & state=="ASSAM"
replace block = "NA-DUAR" if block=="NADUAR" & district=="SONITPUR" & state=="ASSAM"
replace block = "FORBESGANJ" if block=="FORBISGANJ" & district=="ARARIA" & state=="BIHAR"
replace block = "KURSAKATTA" if block=="KURSAKANTA" & district=="ARARIA" & state=="BIHAR"
replace block = "DAUDNAGAR" if block=="DOUDNAGAR" & district=="AURANGABAD" & state=="BIHAR"
replace block = "NABINAGAR" if block=="NAVINAGAR" & district=="AURANGABAD" & state=="BIHAR"
replace block = "BAUSI" if block=="BOUNSI" & district=="BANKA" & state=="BIHAR"
replace block = "CHANAN" if block=="CHANDAN" & district=="BANKA" & state=="BIHAR"
replace block = "DHURAIYA" if block=="DHORAIYA" & district=="BANKA" & state=="BIHAR"
replace block = "KATORIA" if block=="KATORIYA" & district=="BANKA" & state=="BIHAR"
replace block = "RAJAUN" if block=="RAJOUN" & district=="BANKA" & state=="BIHAR"
replace block = "CHERIA BARIARPUR" if block=="CHERIYA BARIYARPUR" & district=="BEGUSARAI" & state=="BIHAR"
replace block = "CHHORAHI" if block=="CHHAURAHI" & district=="BEGUSARAI" & state=="BIHAR"
replace block = "KHUDABANDPUR" if block=="KHODAWANDPUR" & district=="BEGUSARAI" & state=="BIHAR"
replace block = "MANSURCHAK" if block=="MANSOORCHAK" & district=="BEGUSARAI" & state=="BIHAR"
replace block = "NARAYANPUR" if block=="NARAINPUR" & district=="BHAGALPUR" & state=="BIHAR"
replace block = "NATHNAGAR" if block=="NATH NAGAR" & district=="BHAGALPUR" & state=="BIHAR"
replace block = "SONHAULA" if block=="SANHAULA" & district=="BHAGALPUR" & state=="BIHAR"
replace block = "SULTANGANJ" if block=="SULATANGANJ" & district=="BHAGALPUR" & state=="BIHAR"
replace block = "ARRAH" if block=="ARA" & district=="BHOJPUR" & state=="BIHAR"
replace block = "BARHARA" if block=="BARHAHARA" & district=="BHOJPUR" & state=="BIHAR"
replace block = "CHARPOKHARI" if block=="CHARPOKHARY" & district=="BHOJPUR" & state=="BIHAR"
replace block = "GARHANI" if block=="GRAHANI" & district=="BHOJPUR" & state=="BIHAR"
replace block = "UDWANT NAGAR" if block=="UDWANTNAGAR" & district=="BHOJPUR" & state=="BIHAR"
replace block = "BARHAMPUR" if block=="BRAHAMPUR" & district=="BUXAR" & state=="BIHAR"
replace block = "CHAUGAIN" if block=="CHAUGAI" & district=="BUXAR" & state=="BIHAR"
replace block = "CHAUSA" if block=="CHOUSA" & district=="BUXAR" & state=="BIHAR"
replace block = "HANUMANNAGAR" if block=="HANUMAN NAGAR" & district=="DARBHANGA" & state=="BIHAR"
replace block = "TAN KUPPA" if block=="TANKUPPA" & district=="GAYA" & state=="BIHAR"
replace block = "BHOREY" if block=="BHORE" & district=="GOPALGANJ" & state=="BIHAR"
replace block = "KATIYA" if block=="KATEYA" & district=="GOPALGANJ" & state=="BIHAR"
replace block = "PHULWARIA" if block=="PHULWARIYA" & district=="GOPALGANJ" & state=="BIHAR"
replace block = "UCHKAGAON" if block=="UCHAKAGAON" & district=="GOPALGANJ" & state=="BIHAR"
replace block = "GHOSHI" if block=="GHOSI" & district=="JEHANABAD" & state=="BIHAR"
replace block = "AZAMNAGAR" if block=="AJAMNAGAR" & district=="KATIHAR" & state=="BIHAR"
replace block = "BELDAUR" if block=="BELDOUR" & district=="KHAGARIA" & state=="BIHAR"
replace block = "GOGRI" if block=="GOGARI" & district=="KHAGARIA" & state=="BIHAR"
replace block = "MANSI" if block=="MANSHI" & district=="KHAGARIA" & state=="BIHAR"
replace block = "DIGHALBANK" if block=="DIGHAL BANK" & district=="KISHANGANJ" & state=="BIHAR"
replace block = "KOCHADHAMIN" if block=="KOCHADHAMAN" & district=="KISHANGANJ" & state=="BIHAR"
replace block = "TERHAGACHH" if block=="TERHA GACHH" & district=="KISHANGANJ" & state=="BIHAR"
replace block = "SURAJGARHA" if block=="SURYAGARHA" & district=="LAKHISARAI" & state=="BIHAR"
replace block = "CHAUSA" if block=="CHOUSA" & district=="MADHEPURA" & state=="BIHAR"
replace block = "GAMHARIA" if block=="GAMHARIYA" & district=="MADHEPURA" & state=="BIHAR"
replace block = "GHAILARH" if block=="GHAILAD" & district=="MADHEPURA" & state=="BIHAR"
replace block = "ANDHRATHARHI" if block=="ANDHARATHADHI" & district=="MADHUBANI" & state=="BIHAR"
replace block = "LAKHNAUR" if block=="LAKHANAUR" & district=="MADHUBANI" & state=="BIHAR"
replace block = "TETIHA BAMBOR" if block=="TETIA BAMBER" & district=="MUNGER" & state=="BIHAR"
replace block = "MUSAHARI" if block=="MUSAHRI" & district=="MUZAFFARPUR" & state=="BIHAR"
replace block = "EKANGARSARAI" if block=="EKANGAR SARAI" & district=="NALANDA" & state=="BIHAR"
replace block = "GIRIAK" if block=="GIRIYAK" & district=="NALANDA" & state=="BIHAR"
replace block = "KARAI PARSURAI" if block=="KARAIPARSURAI" & district=="NALANDA" & state=="BIHAR"
replace block = "NAGAR NAUSA" if block=="NAGARNAUSA" & district=="NALANDA" & state=="BIHAR"
replace block = "PARBALPUR" if block=="PARWALPUR" & district=="NALANDA" & state=="BIHAR"
replace block = "GOBINDPUR" if block=="GOVINDPUR" & district=="NAWADA" & state=="BIHAR"
replace block = "KASHI CHAK" if block=="KASHICHAK" & district=="NAWADA" & state=="BIHAR"
replace block = "KAWAKOL" if block=="KAUAKOAL" & district=="NAWADA" & state=="BIHAR"
replace block = "MAINATANR" if block=="MAINATAND" & district=="PASHCHIM CHAMPARAN" & state=="BIHAR"
replace block = "THAKRAHAN" if block=="THAKARAHAN" & district=="PASHCHIM CHAMPARAN" & state=="BIHAR"
replace block = "BAKHTIARPUR" if block=="BAKHTIYARPUR" & district=="PATNA" & state=="BIHAR"
replace block = "BELCHHI" if block=="BELCHI" & district=="PATNA" & state=="BIHAR"
replace block = "DANIAWAN" if block=="DANIYAWAN" & district=="PATNA" & state=="BIHAR"
replace block = "DULHIN BAZAR" if block=="DULHINBAZAR" & district=="PATNA" & state=="BIHAR"
replace block = "MOKAMEH" if block=="MOKAMA" & district=="PATNA" & state=="BIHAR"
replace block = "HARSIDHI" if block=="HARSIDDHI" & district=="PURBA CHAMPARAN" & state=="BIHAR"
replace block = "PAKRI DAYAL" if block=="PAKRIDAYAL" & district=="PURBA CHAMPARAN" & state=="BIHAR"
replace block = "PIPRAKOTHI" if block=="PIPRA KOTHI" & district=="PURBA CHAMPARAN" & state=="BIHAR"
replace block = "AMOUR" if block=="AMAUR" & district=="PURNIA" & state=="BIHAR"
replace block = "SRINAGAR" if block=="SRI NAGAR" & district=="PURNIA" & state=="BIHAR"
replace block = "AKORHI GOLA" if block=="AKODHIGOLA" & district=="ROHTAS" & state=="BIHAR"
replace block = "NAUHATTA" if block=="NAWHATTA" & district=="ROHTAS" & state=="BIHAR"
replace block = "SHEOSAGAR" if block=="SHIVSAGAR" & district=="ROHTAS" & state=="BIHAR"
replace block = "TILOUTHU" if block=="TILAUTHU" & district=="ROHTAS" & state=="BIHAR"
replace block = "BANMA ITAHRI" if block=="BANMA ITAHARI" & district=="SAHARSA" & state=="BIHAR"
replace block = "SATAR KATAIYA" if block=="SATTAR KATTAIYA" & district=="SAHARSA" & state=="BIHAR"
replace block = "SIMRI BAKHTIARPUR" if block=="SIMRI BAKHTIYARPUR" & district=="SAHARSA" & state=="BIHAR"
replace block = "BIBHUTPUR" if block=="BIBHUTIPUR" & district=="SAMASTIPUR" & state=="BIHAR"
replace block = "MOHIUDDINAGAR" if block=="MOHIUDDIN NAGAR" & district=="SAMASTIPUR" & state=="BIHAR"
replace block = "SHIVAJI NAGAR" if block=="SHIVAJINAGAR" & district=="SAMASTIPUR" & state=="BIHAR"
replace block = "UJIARPUR" if block=="UJIYARPUR" & district=="SAMASTIPUR" & state=="BIHAR"
replace block = "VIDYAPATI NAGAR" if block=="VIDYAPATINAGAR" & district=="SAMASTIPUR" & state=="BIHAR"
replace block = "ISHUPUR" if block=="ISHUAPUR" & district=="SARAN" & state=="BIHAR"
replace block = "MASHRAKH" if block=="MASRAK" & district=="SARAN" & state=="BIHAR"
replace block = "REVELGANJ" if block=="REVILGANJ" & district=="SARAN" & state=="BIHAR"
replace block = "ARIARI" if block=="ARIYARI" & district=="SHEIKHPURA" & state=="BIHAR"
replace block = "SHEIKHPURA" if block=="SHEKHPURA" & district=="SHEIKHPURA" & state=="BIHAR"
replace block = "BOKHARA" if block=="BOKHRA" & district=="SITAMARHI" & state=="BIHAR"
replace block = "CHARAUT" if block=="CHORAUT" & district=="SITAMARHI" & state=="BIHAR"
replace block = "RUNISAIDPUR" if block=="RUNNI SAIDPUR" & district=="SITAMARHI" & state=="BIHAR"
replace block = "BHAGWANPUR HAT" if block=="BHAGWANPUR HATT" & district=="SIWAN" & state=="BIHAR"
replace block = "DARAUNDHA" if block=="DARAUNDA" & district=="SIWAN" & state=="BIHAR"
replace block = "GORIAKOTHI" if block=="GOREA KOTHI" & district=="SIWAN" & state=="BIHAR"
replace block = "LAKRI NABIGANJ" if block=="LAKRINAVIGANJ" & district=="SIWAN" & state=="BIHAR"
replace block = "SARAIGARH BHAPTIYAHI" if block=="SARAIGARH BHAPTIAHI" & district=="SUPAUL" & state=="BIHAR"
replace block = "BHAGWANPUR" if block=="BHAGAWANPUR" & district=="VAISHALI" & state=="BIHAR"
replace block = "CHEHRA KALAN" if block=="CHEHRAKALAN" & district=="VAISHALI" & state=="BIHAR"
replace block = "DESRI" if block=="DESHRI" & district=="VAISHALI" & state=="BIHAR"
replace block = "PATERHI BELSAR" if block=="PATEDHI BELSAR" & district=="VAISHALI" & state=="BIHAR"
replace block = "RAJA PAKAR" if block=="RAJAPAKAR" & district=="VAISHALI" & state=="BIHAR"
replace block = "SAHDAI BUZURG" if block=="SAHDEI BUZURG" & district=="VAISHALI" & state=="BIHAR"
replace block = "BEMETRA" if block=="BEMETARA" & district=="DURG" & state=="CHHATTISGARH"
replace block = "SARAIPALI" if block=="SARAYPALI" & district=="MAHASAMUND" & state=="CHHATTISGARH"
replace block = "BARWALA" if block=="BARVALA" & district=="AHMADABAD" & state=="GUJARAT"
replace block = "BARWALA" if block=="BAVALA" & district=="AHMADABAD" & state=="GUJARAT"
replace block = "DASKROI" if block=="DASCROI" & district=="AHMADABAD" & state=="GUJARAT"
replace block = "BABRA" if block=="BABARA" & district=="AMRELI" & state=="GUJARAT"
replace block = "LILIA" if block=="LILIYA" & district=="AMRELI" & state=="GUJARAT"
replace block = "SAVAR KUNDLA" if block=="SAVARKUNDLA" & district=="AMRELI" & state=="GUJARAT"
replace block = "KANKREJ" if block=="KANKAREJ" & district=="BANAS KANTHA" & state=="GUJARAT"
replace block = "ANKLESVAR" if block=="ANKLESHWAR" & district=="BHARUCH" & state=="GUJARAT"
replace block = "GARIADHAR" if block=="GARIYADHAR" & district=="BHAVNAGAR" & state=="GUJARAT"
replace block = "SIHOR" if block=="SHIHOR" & district=="BHAVNAGAR" & state=="GUJARAT"
replace block = "VALLABHIPUR" if block=="VALLBHIPUR" & district=="BHAVNAGAR" & state=="GUJARAT"
replace block = "JHALOD" if block=="ZALOD" & district=="DOHAD" & state=="GUJARAT"
replace block = "LAKHPAT" if block=="LAKHAPAT" & district=="KACHCHH" & state=="GUJARAT"
replace block = "THASRA" if block=="THASARA" & district=="KHEDA" & state=="GUJARAT"
replace block = "MAHESANA" if block=="MEHSANA" & district=="MAHESANA" & state=="GUJARAT"
replace block = "DEDIAPADA" if block=="DEDIYAPADA" & district=="NARMADA" & state=="GUJARAT"
replace block = "TILAKWADA" if block=="TILAKVADA" & district=="NARMADA" & state=="GUJARAT"
replace block = "JALALPORE" if block=="JALALPOR" & district=="NAVSARI" & state=="GUJARAT"
replace block = "SHEHERA" if block=="SHAHERA" & district=="PANCH MAHALS" & state=="GUJARAT"
replace block = "CHANASMA" if block=="CHANSMA" & district=="PATAN" & state=="GUJARAT"
replace block = "SIDHPUR" if block=="SIDDHPUR" & district=="PATAN" & state=="GUJARAT"
replace block = "MORVI" if block=="MORBI" & district=="RAJKOT" & state=="GUJARAT"
replace block = "HIMATNAGAR" if block=="HIMMATNAGAR" & district=="SABAR KANTHA" & state=="GUJARAT"
replace block = "CHORASI" if block=="CHORYASI" & district=="SURAT" & state=="GUJARAT"
replace block = "MANDVI" if block=="MANDAVI" & district=="SURAT" & state=="GUJARAT"
replace block = "PALSANA" if block=="PALASANA" & district=="SURAT" & state=="GUJARAT"
replace block = "WADHWAN" if block=="WADHVAN" & district=="SURENDRANAGAR" & state=="GUJARAT"
replace block = "JETPUR PAVI" if block=="JETPUR-PAVI" & district=="VADODARA" & state=="GUJARAT"
replace block = "KAVANT" if block=="KAWANT" & district=="VADODARA" & state=="GUJARAT"
replace block = "NASVADI" if block=="NASWADI" & district=="VADODARA" & state=="GUJARAT"
replace block = "SINOR" if block=="SHINOR" & district=="VADODARA" & state=="GUJARAT"
replace block = "VAGHODIA" if block=="VAGHODIYA" & district=="VADODARA" & state=="GUJARAT"
replace block = "KAPRADA" if block=="KAPARADA" & district=="VALSAD" & state=="GUJARAT"
replace block = "AMBALA" if block=="AMBALA 1" & district=="AMBALA" & state=="HARYANA"
replace block = "PUNAHANA" if block=="PUNHANA" & district=="GURGAON" & state=="HARYANA"
replace block = "MAHENDRAGARH" if block=="MAHENDERGARH" & district=="MAHENDRAGARH" & state=="HARYANA"
replace block = "MAHAM" if block=="MEHAM" & district=="ROHTAK" & state=="HARYANA"
replace block = "SONIPAT" if block=="SONEPAT" & district=="SONIPAT" & state=="HARYANA"
replace block = "JHANDUTA" if block=="JHANDUTTA" & district=="BILASPUR" & state=="HIMACHAL PRADESH"
replace block = "SALUNI" if block=="SALOONI" & district=="CHAMBA" & state=="HIMACHAL PRADESH"
replace block = "DHARMSALA" if block=="DHARAMSALA" & district=="KANGRA" & state=="HIMACHAL PRADESH"
replace block = "POO" if block=="POOH" & district=="KINNAUR" & state=="HIMACHAL PRADESH"
replace block = "ANI" if block=="ANNI" & district=="KULLU" & state=="HIMACHAL PRADESH"
replace block = "NERMAND" if block=="NIRMAND" & district=="KULLU" & state=="HIMACHAL PRADESH"
replace block = "DODRA KWAR" if block=="DODRAKAWAR" & district=="SHIMLA" & state=="HIMACHAL PRADESH"
replace block = "KUMHARSAIN" if block=="KUMARSAIN" & district=="SHIMLA" & state=="HIMACHAL PRADESH"
replace block = "NERUA" if block=="NERWA" & district=="SHIMLA" & state=="HIMACHAL PRADESH"
replace block = "TIKAR" if block=="TIKKAR" & district=="SHIMLA" & state=="HIMACHAL PRADESH"
replace block = "SHALAI" if block=="SHILLAI" & district=="SIRMAUR" & state=="HIMACHAL PRADESH"
replace block = "RAMSHAHR" if block=="RAMSHAHAR" & district=="SOLAN" & state=="HIMACHAL PRADESH"
replace block = "DURU" if block=="DORU" & district=="ANANTNAG" & state=="JAMMU & KASHMIR"
replace block = "BADGAM" if block=="BUDGAM" & district=="BADGAM" & state=="JAMMU & KASHMIR"
replace block = "CHADURA" if block=="CHADOORA" & district=="BADGAM" & state=="JAMMU & KASHMIR"
replace block = "BANDIPORE" if block=="BANDIPORA" & district=="BARAMULA" & state=="JAMMU & KASHMIR"
replace block = "BARAMULA" if block=="BARAMULLA" & district=="BARAMULA" & state=="JAMMU & KASHMIR"
replace block = "BANIHAL" if block=="BANHAL" & district=="DODA" & state=="JAMMU & KASHMIR"
replace block = "THATHRI" if block=="THATRI" & district=="DODA" & state=="JAMMU & KASHMIR"
replace block = "BISHNA" if block=="BISHNAH" & district=="JAMMU" & state=="JAMMU & KASHMIR"
replace block = "BASHOHLI" if block=="BASHOLI" & district=="KATHUA" & state=="JAMMU & KASHMIR"
replace block = "PAMPORE" if block=="PAMPORA" & district=="PULWAMA" & state=="JAMMU & KASHMIR"
replace block = "SHUPIYAN" if block=="SHOPIAN" & district=="PULWAMA" & state=="JAMMU & KASHMIR"
replace block = "NOWSHEHRA" if block=="NOWSHERA" & district=="RAJAURI" & state=="JAMMU & KASHMIR"
replace block = "RAJAURI" if block=="RAJOURI" & district=="RAJAURI" & state=="JAMMU & KASHMIR"
replace block = "GUMIA" if block=="GOMIYA" & district=="BOKARO" & state=="JHARKHAND"
replace block = "PETERUAR" if block=="PETARWAR" & district=="BOKARO" & state=="JHARKHAND"
replace block = "LAWALAUNG" if block=="LAWALONG" & district=="CHATRA" & state=="JHARKHAND"
replace block = "PATHALGORA" if block=="PATHALGADA" & district=="CHATRA" & state=="JHARKHAND"
replace block = "KARON" if block=="KARO" & district=="DEOGHAR" & state=="JHARKHAND"
replace block = "KARON" if block=="KAROWN" & district=="DEOGHAR" & state=="JHARKHAND"
replace block = "GOBINDPUR" if block=="GOVINDPUR" & district=="DHANBAD" & state=="JHARKHAND"
replace block = "BHANDARIA" if block=="BHANDRIYA" & district=="GARHWA" & state=="JHARKHAND"
replace block = "BHAWNATHPUR" if block=="BHAWANATHPUR" & district=="GARHWA" & state=="JHARKHAND"
replace block = "DANDAI" if block=="DANDA" & district=="GARHWA" & state=="JHARKHAND"
replace block = "DANDAI" if block=="DANDEY" & district=="GARHWA" & state=="JHARKHAND"
replace block = "MAJHIAON" if block=="MAJHIGAOWN" & district=="GARHWA" & state=="JHARKHAND"
replace block = "NAGARUNTARI" if block=="NAGARUTARI" & district=="GARHWA" & state=="JHARKHAND"
replace block = "BIRNI" if block=="BIRANI" & district=="GIRIDIH" & state=="JHARKHAND"
replace block = "DUMRI" if block=="DUMARI" & district=="GIRIDIH" & state=="JHARKHAND"
replace block = "GANDE" if block=="GANDEY" & district=="GIRIDIH" & state=="JHARKHAND"
replace block = "PIRTANR" if block=="PIRTAND" & district=="GIRIDIH" & state=="JHARKHAND"
replace block = "BOARIJOR" if block=="BOARIJORE" & district=="GODDA" & state=="JHARKHAND"
replace block = "MEHERMA" if block=="MEHARMA" & district=="GODDA" & state=="JHARKHAND"
replace block = "POREYAHAT" if block=="PORAIYAHAT" & district=="GODDA" & state=="JHARKHAND"
replace block = "SUNDARPAHARI" if block=="SUNDERPAHARI" & district=="GODDA" & state=="JHARKHAND"
replace block = "THAKUR GANGTI" if block=="THAKUR GANGATI" & district=="GODDA" & state=="JHARKHAND"
replace block = "THAKUR GANGTI" if block=="THAKURGANGATI" & district=="GODDA" & state=="JHARKHAND"
replace block = "BANO" if block=="BHARNO" & district=="GUMLA" & state=="JHARKHAND"
replace block = "BISHUNGARH" if block=="BISHNUGARH" & district=="HAZARIBAGH" & state=="JHARKHAND"
replace block = "HAZARIBAG" if block=="HAZARIBAGH" & district=="HAZARIBAGH" & state=="JHARKHAND"
replace block = "KODARMA" if block=="KODERMA" & district=="KODARMA" & state=="JHARKHAND"
replace block = "MARKACHO" if block=="MARKACHHO" & district=="KODARMA" & state=="JHARKHAND"
replace block = "AMRAPARA" if block=="AMRA PARA" & district=="PAKAUR" & state=="JHARKHAND"
replace block = "HIRANPUR" if block=="HIRAN PUR" & district=="PAKAUR" & state=="JHARKHAND"
replace block = "LITIPARA" if block=="LITTI PARA" & district=="PAKAUR" & state=="JHARKHAND"
replace block = "MAHESHPUR" if block=="MAHESH PUR" & district=="PAKAUR" & state=="JHARKHAND"
replace block = "PAKURIA" if block=="PAKURIYA" & district=="PAKAUR" & state=="JHARKHAND"
replace block = "HUSSAINABAD" if block=="HUSAINABAD" & district=="PALAMU" & state=="JHARKHAND"
replace block = "LESLIEGANJ" if block=="LESLIGANJ" & district=="PALAMU" & state=="JHARKHAND"
replace block = "GOILKERA" if block=="GOELKERA" & district=="PASHCHIMI SINGHBHUM" & state=="JHARKHAND"
replace block = "BAHARAGORA" if block=="BAHRAGORA" & district=="PURBI SINGHBHUM" & state=="JHARKHAND"
replace block = "BARHAIT" if block=="BARHET" & district=="SAHIBGANJ" & state=="JHARKHAND"
replace block = "BILGI" if block=="BILAGI" & district=="BAGALKOT" & state=="KARNATAKA"
replace block = "HUNGUND" if block=="HUNAGUND" & district=="BAGALKOT" & state=="KARNATAKA"
replace block = "JAMKHANDI" if block=="JAMAKHANDI" & district=="BAGALKOT" & state=="KARNATAKA"
replace block = "RAMANAGARAM" if block=="RAMANAGARA" & district=="BANGALORE RURAL" & state=="KARNATAKA"
replace block = "ATHNI" if block=="ATHANI" & district=="BELGAUM" & state=="KARNATAKA"
replace block = "HUKERI" if block=="HUKKERI" & district=="BELGAUM" & state=="KARNATAKA"
replace block = "RAYBAG" if block=="RAIBAG" & district=="BELGAUM" & state=="KARNATAKA"
replace block = "HADAGALLI" if block=="HADAGALI" & district=="BELLARY" & state=="KARNATAKA"
replace block = "HOMNABAD" if block=="HUMNABAD" & district=="BIDAR" & state=="KARNATAKA"
replace block = "BASAVANA BAGEVADI" if block=="BASAVAN BAGEWADI" & district=="BIJAPUR" & state=="KARNATAKA"
replace block = "SINDGI" if block=="SINDAGI" & district=="BIJAPUR" & state=="KARNATAKA"
replace block = "CHAMARAJANAGAR" if block=="CHAMARAJA NAGAR" & district=="CHAMARAJANAGAR" & state=="KARNATAKA"
replace block = "GUNDLUPET" if block=="GUNDULPET" & district=="CHAMARAJANAGAR" & state=="KARNATAKA"
replace block = "MUDIGERE" if block=="MOODIGERE" & district=="CHIKMAGALUR" & state=="KARNATAKA"
replace block = "MOLAKALMURU" if block=="MOLAKALMUR" & district=="CHITRADURGA" & state=="KARNATAKA"
replace block = "BANTVAL" if block=="BANTWAL" & district=="DAKSHINA KANNADA" & state=="KARNATAKA"
replace block = "BELTANGADI" if block=="BELTHANGADY" & district=="DAKSHINA KANNADA" & state=="KARNATAKA"
replace block = "SULYA" if block=="SULLIA" & district=="DAKSHINA KANNADA" & state=="KARNATAKA"
replace block = "HARIHAR" if block=="HARIHARA" & district=="DAVANAGERE" & state=="KARNATAKA"
replace block = "KALGHATGI" if block=="KALGHATAGI" & district=="DHARWAD" & state=="KARNATAKA"
replace block = "KUNDGOL" if block=="KUNDAGOL" & district=="DHARWAD" & state=="KARNATAKA"
replace block = "MUNDARGI" if block=="MUNDARAGI" & district=="GADAG" & state=="KARNATAKA"
replace block = "NARGUND" if block=="NARAGUND" & district=="GADAG" & state=="KARNATAKA"
replace block = "CHITAPUR" if block=="CHITTAPUR" & district=="GULBARGA" & state=="KARNATAKA"
replace block = "JEVARGI" if block=="JEWARGI" & district=="GULBARGA" & state=="KARNATAKA"
replace block = "SHAHPUR" if block=="SHAHAPUR" & district=="GULBARGA" & state=="KARNATAKA"
replace block = "BYADGI" if block=="BYADAGI" & district=="HAVERI" & state=="KARNATAKA"
replace block = "HANGAL" if block=="HANAGAL" & district=="HAVERI" & state=="KARNATAKA"
replace block = "RANIBENNUR" if block=="RANEBENNUR" & district=="HAVERI" & state=="KARNATAKA"
replace block = "RANIBENNUR" if block=="RANNEBENNUR" & district=="HAVERI" & state=="KARNATAKA"
replace block = "SHIGGAON" if block=="SHIGGOAN" & district=="HAVERI" & state=="KARNATAKA"
replace block = "SOMVARPET" if block=="SOMAVARPET" & district=="KODAGU" & state=="KARNATAKA"
replace block = "BAGEPALLI" if block=="BAGEPALLY" & district=="KOLAR" & state=="KARNATAKA"
replace block = "BANGARAPET" if block=="BANGARAPETE" & district=="KOLAR" & state=="KARNATAKA"
replace block = "CHIK BALLAPUR" if block=="CHIKKABALLAPUR" & district=="KOLAR" & state=="KARNATAKA"
replace block = "GAURIBIDANUR" if block=="GOWRIBIDANUR" & district=="KOLAR" & state=="KARNATAKA"
replace block = "SRINIVASPUR" if block=="SRINIVASAPUR" & district=="KOLAR" & state=="KARNATAKA"
replace block = "GANGAWATI" if block=="GANGAVATHI" & district=="KOPPAL" & state=="KARNATAKA"
replace block = "KUSHTAGI" if block=="KUSTAGI" & district=="KOPPAL" & state=="KARNATAKA"
replace block = "YELBARGA" if block=="YELBURGA" & district=="KOPPAL" & state=="KARNATAKA"
replace block = "KRISHNARAJPET" if block=="KRISHNARAJA PET" & district=="MANDYA" & state=="KARNATAKA"
replace block = "MALAVALLI" if block=="MALAVALLY" & district=="MANDYA" & state=="KARNATAKA"
replace block = "NANJANGUD" if block=="NANJANAGUD" & district=="MYSORE" & state=="KARNATAKA"
replace block = "PIRIYAPATNA" if block=="PERIYA PATNA" & district=="MYSORE" & state=="KARNATAKA"
replace block = "LINGSUGUR" if block=="LINGASUGUR" & district=="RAICHUR" & state=="KARNATAKA"
replace block = "SINDHNUR" if block=="SINDHANUR" & district=="RAICHUR" & state=="KARNATAKA"
replace block = "HOSANAGARA" if block=="HOSANAGAR" & district=="SHIMOGA" & state=="KARNATAKA"
replace block = "SHIKARPUR" if block=="SHIKARIPUR" & district=="SHIMOGA" & state=="KARNATAKA"
replace block = "TIRTHAHALLI" if block=="THIRTHAHALLI" & district=="SHIMOGA" & state=="KARNATAKA"
replace block = "KARKAL" if block=="KARKALA" & district=="UDUPI" & state=="KARNATAKA"
replace block = "HONAVAR" if block=="HONNAVAR" & district=="UTTARA KANNADA" & state=="KARNATAKA"
replace block = "MUNDGOD" if block=="MUNDAGOD" & district=="UTTARA KANNADA" & state=="KARNATAKA"
replace block = "PEERUMADE" if block=="PEERMADU" & district=="IDUKKI" & state=="KERALA"
replace block = "VADAKARA" if block=="VATAKARA" & district=="KOZHIKODE" & state=="KERALA"
replace block = "MANNARKAD" if block=="MANNNARKKAD" & district=="PALAKKAD" & state=="KERALA"
replace block = "OTTAPPALAM" if block=="OTTAPALAM" & district=="PALAKKAD" & state=="KERALA"
replace block = "KOZHENCHERY" if block=="KOZHENCHERRY" & district=="PATHANAMTHITTA" & state=="KERALA"
replace block = "MALLAPPALLY" if block=="MALLAPALLY" & district=="PATHANAMTHITTA" & state=="KERALA"
replace block = "SULTHANBATHERY" if block=="SULTHAN BATTERY" & district=="WAYANAD" & state=="KERALA"
replace block = "WARASEONI" if block=="WARA SEONI" & district=="BALAGHAT" & state=="MADHYA PRADESH"
replace block = "RAJPUR" if block=="RAJ PUR" & district=="BARWANI" & state=="MADHYA PRADESH"
replace block = "RON" if block=="ROUN" & district=="BHIND" & state=="MADHYA PRADESH"
replace block = "AMARWARA" if block=="AMARWADA" & district=="CHHINDWARA" & state=="MADHYA PRADESH"
replace block = "CHAURAI" if block=="CHOURAI" & district=="CHHINDWARA" & state=="MADHYA PRADESH"
replace block = "TONK KHURD" if block=="TONKKHURD" & district=="DEWAS" & state=="MADHYA PRADESH"
replace block = "BADNAWAR" if block=="BADNAVAR" & district=="DHAR" & state=="MADHYA PRADESH"
replace block = "MANAWAR" if block=="MANAVAR" & district=="DHAR" & state=="MADHYA PRADESH"
replace block = "PIPARIYA" if block=="PIPERIYA" & district=="HOSHANGABAD" & state=="MADHYA PRADESH"
replace block = "SAWER" if block=="SANWER" & district=="INDORE" & state=="MADHYA PRADESH"
replace block = "BHAVRA" if block=="BHABARA" & district=="JHABUA" & state=="MADHYA PRADESH"
replace block = "DHIMAR KHEDA" if block=="DHEEMAR KHEDA" & district=="KATNI" & state=="MADHYA PRADESH"
replace block = "VIJAYRAGHAVGARH" if block=="VIJAY RAGHAVGARH" & district=="KATNI" & state=="MADHYA PRADESH"
replace block = "BICHHIYA" if block=="BICHHIA" & district=="MANDLA" & state=="MADHYA PRADESH"
replace block = "GUNNOR" if block=="GUNOUR" & district=="PANNA" & state=="MADHYA PRADESH"
replace block = "JIRAPUR" if block=="ZIRAPUR" & district=="RAJGARH" & state=="MADHYA PRADESH"
replace block = "BINA" if block=="BEENA" & district=="SAGAR" & state=="MADHYA PRADESH"
replace block = "RAMNAGAR" if block=="RAM NAGAR" & district=="SATNA" & state=="MADHYA PRADESH"
replace block = "RAMPUR-BAGHELAN" if block=="RAMPUR BAGHELAN" & district=="SATNA" & state=="MADHYA PRADESH"
replace block = "UNCHEHARA" if block=="UNCHERA" & district=="SATNA" & state=="MADHYA PRADESH"
replace block = "BUDNI" if block=="BUDHANI" & district=="SEHORE" & state=="MADHYA PRADESH"
replace block = "PUSHPARAJGARH" if block=="PUSHPRAJ GARH" & district=="SHAHDOL" & state=="MADHYA PRADESH"
replace block = "BADOD" if block=="BAROD" & district=="SHAJAPUR" & state=="MADHYA PRADESH"
replace block = "KARERA" if block=="KARAIRA" & district=="SHIVPURI" & state=="MADHYA PRADESH"
replace block = "NARWAR" if block=="NARVAR" & district=="SHIVPURI" & state=="MADHYA PRADESH"
replace block = "POHARI" if block=="POHRI" & district=="SHIVPURI" & state=="MADHYA PRADESH"
replace block = "CHITRANGI" if block=="CHITARANGI" & district=="SIDHI" & state=="MADHYA PRADESH"
replace block = "KUSMI" if block=="KUSAMI" & district=="SIDHI" & state=="MADHYA PRADESH"
replace block = "MAJHOLI" if block=="MAJHAULI" & district=="SIDHI" & state=="MADHYA PRADESH"
replace block = "BALDEOGARH" if block=="BALDEWGARH" & district=="TIKAMGARH" & state=="MADHYA PRADESH"
replace block = "PRITHVIPUR" if block=="PRATHVIPUR" & district=="TIKAMGARH" & state=="MADHYA PRADESH"
replace block = "BADNAGAR" if block=="BARNAGAR" & district=="UJJAIN" & state=="MADHYA PRADESH"
replace block = "GHATIYA" if block=="GHATTIA" & district=="UJJAIN" & state=="MADHYA PRADESH"
replace block = "KHACHAROD" if block=="KHACHROD" & district=="UJJAIN" & state=="MADHYA PRADESH"
replace block = "BARWAHA" if block=="BADWAHA" & district=="WEST NIMAR" & state=="MADHYA PRADESH"
replace block = "BHAGWANPURA" if block=="BHAGBANPURA" & district=="WEST NIMAR" & state=="MADHYA PRADESH"
replace block = "JHIRANYA" if block=="JHIRNIYA" & district=="WEST NIMAR" & state=="MADHYA PRADESH"
replace block = "KASRAWAD" if block=="KASRAVAD" & district=="WEST NIMAR" & state=="MADHYA PRADESH"
replace block = "AKOLA" if block=="AKOLE" & district=="AHMADNAGAR" & state=="MAHARASHTRA"
replace block = "NEVASA" if block=="NEWASA" & district=="AHMADNAGAR" & state=="MAHARASHTRA"
replace block = "RAHTA" if block=="RAHATA" & district=="AHMADNAGAR" & state=="MAHARASHTRA"
replace block = "SHRIRAMPUR" if block=="SHRIRAMPOOR" & district=="AHMADNAGAR" & state=="MAHARASHTRA"
replace block = "MURTIJAPUR" if block=="MURTIZAPUR" & district=="AKOLA" & state=="MAHARASHTRA"
replace block = "TEOSA" if block=="TIOSA" & district=="AMRAVATI" & state=="MAHARASHTRA"
replace block = "KHULDABAD" if block=="KHULTABAD" & district=="AURANGABAD" & state=="MAHARASHTRA"
replace block = "AMBEJOGAI" if block=="AMBAJOGAI" & district=="BID" & state=="MAHARASHTRA"
replace block = "BID" if block=="BEED" & district=="BID" & state=="MAHARASHTRA"
replace block = "DEOLGAON RAJA" if block=="DEOULGAON RAJA" & district=="BULDANA" & state=="MAHARASHTRA"
replace block = "JALGAON (JAMOD)" if block=="JALGAON JAMOD" & district=="BULDANA" & state=="MAHARASHTRA"
replace block = "MEHKAR" if block=="MEHEKAR" & district=="BULDANA" & state=="MAHARASHTRA"
replace block = "BHADRAVATI" if block=="BHADRAWATI" & district=="CHANDRAPUR" & state=="MAHARASHTRA"
replace block = "BRAHMAPURI" if block=="BRAMHAPURI" & district=="CHANDRAPUR" & state=="MAHARASHTRA"
replace block = "GONDPIPRI" if block=="GONDPIPARI" & district=="CHANDRAPUR" & state=="MAHARASHTRA"
replace block = "NAGBHIR" if block=="NAGBHID" & district=="CHANDRAPUR" & state=="MAHARASHTRA"
replace block = "SAWALI" if block=="SAOLI" & district=="CHANDRAPUR" & state=="MAHARASHTRA"
replace block = "SINDKHEDE" if block=="SHINDKHEDA" & district=="DHULE" & state=="MAHARASHTRA"
replace block = "GONDIYA" if block=="GONDIA" & district=="GONDIYA" & state=="MAHARASHTRA"
replace block = "SADAK-ARJUNI" if block=="SADAK ARJUNI" & district=="GONDIYA" & state=="MAHARASHTRA"
replace block = "TIRORA" if block=="TIRODA" & district=="GONDIYA" & state=="MAHARASHTRA"
replace block = "AUNDHA (NAGNATH)" if block=="AUNDHA NAGNATH" & district=="HINGOLI" & state=="MAHARASHTRA"
replace block = "BODVAD" if block=="BODWAD" & district=="JALGAON" & state=="MAHARASHTRA"
replace block = "CHOPDA" if block=="CHOPADA" & district=="JALGAON" & state=="MAHARASHTRA"
replace block = "RAVER" if block=="RAWER" & district=="JALGAON" & state=="MAHARASHTRA"
replace block = "JAFFERABAD" if block=="JAFRABAD" & district=="JALNA" & state=="MAHARASHTRA"
replace block = "AJRA" if block=="AAJARA" & district=="KOLHAPUR" & state=="MAHARASHTRA"
replace block = "HATKANANGLE" if block=="HATKALANGLE" & district=="KOLHAPUR" & state=="MAHARASHTRA"
replace block = "KARVIR" if block=="KARVEER" & district=="KOLHAPUR" & state=="MAHARASHTRA"
replace block = "AHMADPUR" if block=="AHAMADPUR" & district=="LATUR" & state=="MAHARASHTRA"
replace block = "DEONI" if block=="DEVANI" & district=="LATUR" & state=="MAHARASHTRA"
replace block = "SHIRUR-ANANTPAL" if block=="SHIRUR ANANTPAL" & district=="LATUR" & state=="MAHARASHTRA"
replace block = "HINGNA" if block=="HINGANA" & district=="NAGPUR" & state=="MAHARASHTRA"
replace block = "KALAMESHWAR" if block=="KALMESHWAR" & district=="NAGPUR" & state=="MAHARASHTRA"
replace block = "MAUDA" if block=="MOUDA" & district=="NAGPUR" & state=="MAHARASHTRA"
replace block = "SAVNER" if block=="SAONER" & district=="NAGPUR" & state=="MAHARASHTRA"
replace block = "DEGLUR" if block=="DEGLOOR" & district=="NANDED" & state=="MAHARASHTRA"
replace block = "HIMAYATNAGAR" if block=="HIMAYAT NAGAR" & district=="NANDED" & state=="MAHARASHTRA"
replace block = "NAWAPUR" if block=="NAVAPUR" & district=="NANDURBAR" & state=="MAHARASHTRA"
replace block = "SHAHADE" if block=="SHAHADA" & district=="NANDURBAR" & state=="MAHARASHTRA"
replace block = "TALODE" if block=="TALODA" & district=="NANDURBAR" & state=="MAHARASHTRA"
replace block = "CHANDVAD" if block=="CHANDWAD" & district=="NASHIK" & state=="MAHARASHTRA"
replace block = "DEOLA" if block=="DEVLA" & district=="NASHIK" & state=="MAHARASHTRA"
replace block = "SINNAR" if block=="SINNER" & district=="NASHIK" & state=="MAHARASHTRA"
replace block = "YEVLA" if block=="YEOLA" & district=="NASHIK" & state=="MAHARASHTRA"
replace block = "BHUM" if block=="BHOOM" & district=="OSMANABAD" & state=="MAHARASHTRA"
replace block = "KALAMB" if block=="KALLAMB" & district=="OSMANABAD" & state=="MAHARASHTRA"
replace block = "MANWATH" if block=="MANWAT" & district=="PARBHANI" & state=="MAHARASHTRA"
replace block = "MAWAL" if block=="MAVAL" & district=="PUNE" & state=="MAHARASHTRA"
replace block = "PURANDHAR" if block=="PURANDAR" & district=="PUNE" & state=="MAHARASHTRA"
replace block = "MHASLA" if block=="MHASALA" & district=="RAIGARH" & state=="MAHARASHTRA"
replace block = "ATPADI" if block=="ATAPADI" & district=="SANGLI" & state=="MAHARASHTRA"
replace block = "JAT" if block=="JATH" & district=="SANGLI" & state=="MAHARASHTRA"
replace block = "KAVATHE-MAHANKAL" if block=="KAVATHE MAHANKAL" & district=="SANGLI" & state=="MAHARASHTRA"
replace block = "MALWAN" if block=="MALVAN" & district=="SINDHUDURG" & state=="MAHARASHTRA"
replace block = "VAIBHAVVADI" if block=="VAIBHAVWADI" & district=="SINDHUDURG" & state=="MAHARASHTRA"
replace block = "VENGURLA" if block=="VENGURLE" & district=="SINDHUDURG" & state=="MAHARASHTRA"
replace block = "MALSHIRAS" if block=="MALSHIRUS" & district=="SOLAPUR" & state=="MAHARASHTRA"
replace block = "MANGALVEDHE" if block=="MANGALWEDHA" & district=="SOLAPUR" & state=="MAHARASHTRA"
replace block = "SANGOLE" if block=="SANGOLA" & district=="SOLAPUR" & state=="MAHARASHTRA"
replace block = "AMBARNATH" if block=="AMBERNATH" & district=="THANE" & state=="MAHARASHTRA"
replace block = "VADA" if block=="WADA" & district=="THANE" & state=="MAHARASHTRA"
replace block = "MANGRULPIR" if block=="MANGARULPIR" & district=="WASHIM" & state=="MAHARASHTRA"
replace block = "BABULGAON" if block=="BABHULGAON" & district=="YAVATMAL" & state=="MAHARASHTRA"
replace block = "DADENGGIRI" if block=="DADENGGRE" & district=="WEST GARO HILLS" & state=="MEGHALAYA"
replace block = "NIULAND" if block=="NUILAND" & district=="DIMAPUR" & state=="NAGALAND"
replace block = "CHANGTONGYA" if block=="CHANGTONGYA-B" & district=="MOKOKCHUNG" & state=="NAGALAND"
replace block = "KUBOLONG" if block=="KOBULONG" & district=="MOKOKCHUNG" & state=="NAGALAND"
replace block = "SEYOCHUNG" if block=="SEYONCHUNG" & district=="TUENSANG" & state=="NAGALAND"
replace block = "PALALAHADA" if block=="PALLAHARA" & district=="ANUGUL" & state=="ORISSA"
replace block = "BELPARA" if block=="BELPADA" & district=="BALANGIR" & state=="ORISSA"
replace block = "LOISINGA" if block=="LOISINGHA" & district=="BALANGIR" & state=="ORISSA"
replace block = "NILAGIRI" if block=="NILGIRI" & district=="BALESHWAR" & state=="ORISSA"
replace block = "BHATLI" if block=="BHATALI" & district=="BARGARH" & state=="ORISSA"
replace block = "PAIKAMAL" if block=="PAIKMAL" & district=="BARGARH" & state=="ORISSA"
replace block = "BASUDEBPUR" if block=="BASUDEV PUR" & district=="BHADRAK" & state=="ORISSA"
replace block = "BHANDARI POKHARI" if block=="BHANDARIPOKHARI" & district=="BHADRAK" & state=="ORISSA"
replace block = "DHAMANAGAR" if block=="DHAMNAGAR" & district=="BHADRAK" & state=="ORISSA"
replace block = "BARANG" if block=="BARANGA" & district=="CUTTACK" & state=="ORISSA"
replace block = "NARASINGHPUR" if block=="NARSINGHPUR" & district=="CUTTACK" & state=="ORISSA"
replace block = "SALEPUR" if block=="SALIPUR" & district=="CUTTACK" & state=="ORISSA"
replace block = "GANDIA" if block=="GONDIA" & district=="DHENKANAL" & state=="ORISSA"
replace block = "PARAJANG" if block=="PARJANG" & district=="DHENKANAL" & state=="ORISSA"
replace block = "R.UDAYGIRI" if block=="R.UDAYAGIRI" & district=="GAJAPATI" & state=="ORISSA"
replace block = "ASIKA" if block=="ASKA" & district=="GANJAM" & state=="ORISSA"
replace block = "KHALIKOTE" if block=="KHALLIKOTE" & district=="GANJAM" & state=="ORISSA"
replace block = "PATAPUR" if block=="PATRAPUR" & district=="GANJAM" & state=="ORISSA"
replace block = "ERSAMA" if block=="ERASAMA" & district=="JAGATSINGHAPUR" & state=="ORISSA"
replace block = "JAGATSINGHAPUR" if block=="JAGATSINGH PUR" & district=="JAGATSINGHAPUR" & state=="ORISSA"
replace block = "JAGATSINGHAPUR" if block=="JAGATSINGHPUR" & district=="JAGATSINGHAPUR" & state=="ORISSA"
replace block = "JAYAPATNA" if block=="JAIPATNA" & district=="KALAHANDI" & state=="ORISSA"
replace block = "KOKASARA" if block=="KOKSARA" & district=="KALAHANDI" & state=="ORISSA"
replace block = "NARALA" if block=="NARLA" & district=="KALAHANDI" & state=="ORISSA"
replace block = "BALIGUDA" if block=="BALLIGUDA" & district=="KANDHAMAL" & state=="ORISSA"
replace block = "AALI" if block=="AUL" & district=="KENDRAPARA" & state=="ORISSA"
replace block = "MAHAKALAPADA" if block=="MAHAKALPARA" & district=="KENDRAPARA" & state=="ORISSA"
replace block = "GHATGAON" if block=="GHATAGAON" & district=="KENDUJHAR" & state=="ORISSA"
replace block = "PATANA" if block=="PATNA" & district=="KENDUJHAR" & state=="ORISSA"
replace block = "BORIGUMA" if block=="BORIGUMMA" & district=="KORAPUT" & state=="ORISSA"
replace block = "DASAMANTAPUR" if block=="DASMANTPUR" & district=="KORAPUT" & state=="ORISSA"
replace block = "KUNDURA" if block=="KUNDRA" & district=="KORAPUT" & state=="ORISSA"
replace block = "NARAYANPATANA" if block=="NARAYANAPATNA" & district=="KORAPUT" & state=="ORISSA"
replace block = "SIMILIGUDA" if block=="SEMILIGUDA" & district=="KORAPUT" & state=="ORISSA"
replace block = "BANGIRIPOSI" if block=="BANGRIPOSI" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "BETANATI" if block=="BETNOTI" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "KOLIANA" if block=="KULIANA" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "MURUDA" if block=="MORADA" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "RASAGOBINDAPUR" if block=="RASAGOVINDPUR" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "TIRINGI" if block=="TIRING" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "DABUGAN" if block=="DABUGAM" & district=="NABARANGAPUR" & state=="ORISSA"
replace block = "JHARIGAN" if block=="JHARIGAM" & district=="NABARANGAPUR" & state=="ORISSA"
replace block = "NABARANGAPUR" if block=="NABARANGPUR" & district=="NABARANGAPUR" & state=="ORISSA"
replace block = "PAPARAHANDI" if block=="PAPADAHANDI" & district=="NABARANGAPUR" & state=="ORISSA"
replace block = "UMARKOTE" if block=="UMERKOTE" & district=="NABARANGAPUR" & state=="ORISSA"
replace block = "RANAPUR" if block=="RANPUR" & district=="NAYAGARH" & state=="ORISSA"
replace block = "KOMANA" if block=="KOMNA" & district=="NUAPADA" & state=="ORISSA"
replace block = "DELANGA" if block=="DELANG" & district=="PURI" & state=="ORISSA"
replace block = "NIMAPADA" if block=="NIMAPARA" & district=="PURI" & state=="ORISSA"
replace block = "KASHIPUR" if block=="KASIPUR" & district=="RAYAGADA" & state=="ORISSA"
replace block = "PADMAPUR" if block=="PADAMPUR" & district=="RAYAGADA" & state=="ORISSA"
replace block = "JUJOMURA" if block=="JUJUMURA" & district=="SAMBALPUR" & state=="ORISSA"
replace block = "KOCHINDA" if block=="KUCHINDA" & district=="SAMBALPUR" & state=="ORISSA"
replace block = "BINIKA" if block=="BINKA" & district=="SONAPUR" & state=="ORISSA"
replace block = "BIRAMAHARAJPUR" if block=="BIRMAHARAJPUR" & district=="SONAPUR" & state=="ORISSA"
replace block = "SONAPUR" if block=="SONEPUR" & district=="SONAPUR" & state=="ORISSA"
replace block = "TARBHA" if block=="TARVA" & district=="SONAPUR" & state=="ORISSA"
replace block = "ULUNDA" if block=="ULLUNDA" & district=="SONAPUR" & state=="ORISSA"
replace block = "HEMGIR" if block=="HEMAGIRI" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "HEMGIR" if block=="HEMGIRI" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "KOIDA" if block=="KOIRA" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "RAJAGANGAPUR" if block=="RAJGANGPUR" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "TANGARAPALI" if block=="TANGARPALI" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "TARN-TARAN" if block=="TARN TARN" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "KHAMANON" if block=="KHAMANO" & district=="FATEHGARH SAHIB" & state=="PUNJAB"
replace block = "FIROZEPUR" if block=="FEROZEPUR" & district=="FIROZPUR" & state=="PUNJAB"
replace block = "DASUA" if block=="DASUYA" & district=="HOSHIARPUR" & state=="PUNJAB"
replace block = "GARHSHANKAR" if block=="GARSHANKAR" & district=="HOSHIARPUR" & state=="PUNJAB"
replace block = "HOSHIARPUR" if block=="HOSHIARPUR 1" & district=="HOSHIARPUR" & state=="PUNJAB"
replace block = "BHAGHA PURANA" if block=="BAGHAPURANA" & district=="MOGA" & state=="PUNJAB"
replace block = "MOGA" if block=="MOGA 1" & district=="MOGA" & state=="PUNJAB"
replace block = "NIHAL SINGHWALA" if block=="NIHAL SINGH WALA" & district=="MOGA" & state=="PUNJAB"
replace block = "GIDDARBAHA" if block=="GIDDERBAHA" & district=="MUKTSAR" & state=="PUNJAB"
replace block = "BHINAY" if block=="BHINAI" & district=="AJMER" & state=="RAJASTHAN"
replace block = "BEHROR" if block=="BEHRORE" & district=="ALWAR" & state=="RAJASTHAN"
replace block = "LACHHMANGARH" if block=="LAKSHMANGARH" & district=="ALWAR" & state=="RAJASTHAN"
replace block = "MANDAWAR" if block=="MUNDAWAR" & district=="ALWAR" & state=="RAJASTHAN"
replace block = "TIJARA" if block=="TIZARA" & district=="ALWAR" & state=="RAJASTHAN"
replace block = "ANTAH" if block=="ANTA" & district=="BARAN" & state=="RAJASTHAN"
replace block = "CHHABRA" if block=="CHABRA" & district=="BARAN" & state=="RAJASTHAN"
replace block = "CHHIPABAROD" if block=="CHIPPABAROD" & district=="BARAN" & state=="RAJASTHAN"
replace block = "CHOHTAN" if block=="CHOHTTAN" & district=="BARMER" & state=="RAJASTHAN"
replace block = "SHEO" if block=="SHIV" & district=="BARMER" & state=="RAJASTHAN"
replace block = "NADBAI" if block=="NADWAI" & district=="BHARATPUR" & state=="RAJASTHAN"
replace block = "KOTRI" if block=="KOTDI" & district=="BHILWARA" & state=="RAJASTHAN"
replace block = "SAHARA" if block=="SAHARDA" & district=="BHILWARA" & state=="RAJASTHAN"
replace block = "CHITTAURGARH" if block=="CHITTORGARH" & district=="CHITTAURGARH" & state=="RAJASTHAN"
replace block = "DHAULPUR" if block=="DHOLPUR" & district=="DHAULPUR" & state=="RAJASTHAN"
replace block = "ANUPGARH" if block=="ANOOPGARH" & district=="GANGANAGAR" & state=="RAJASTHAN"
replace block = "VIJAINAGAR" if block=="VIJAYNAGAR" & district=="GANGANAGAR" & state=="RAJASTHAN"
replace block = "PILIBANGA" if block=="PILIBANGAN" & district=="HANUMANGARH" & state=="RAJASTHAN"
replace block = "SANGARIA" if block=="SANGRIA" & district=="HANUMANGARH" & state=="RAJASTHAN"
replace block = "TIBI" if block=="TIBBI" & district=="HANUMANGARH" & state=="RAJASTHAN"
replace block = "AHORE" if block=="AAHOR" & district=="JALOR" & state=="RAJASTHAN"
replace block = "JALOR" if block=="JALORE" & district=="JALOR" & state=="RAJASTHAN"
replace block = "JHALRAPATAN" if block=="JHALARAPATAN" & district=="JHALAWAR" & state=="RAJASTHAN"
replace block = "MANOHAR THANA" if block=="MANOHARTHANA" & district=="JHALAWAR" & state=="RAJASTHAN"
replace block = "OSIAN" if block=="OSIYAN" & district=="JODHPUR" & state=="RAJASTHAN"
replace block = "LADNU" if block=="LADNUN" & district=="NAGAUR" & state=="RAJASTHAN"
replace block = "MARWAR JUNCTION" if block=="MARVAR JUNCTION" & district=="PALI" & state=="RAJASTHAN"
replace block = "DEOGARH" if block=="DEOGRAH" & district=="RAJSAMAND" & state=="RAJASTHAN"
replace block = "BONLI" if block=="BOUNLI" & district=="SAWAI MADHOPUR" & state=="RAJASTHAN"
replace block = "GANGAPUR" if block=="GANAPUR" & district=="SAWAI MADHOPUR" & state=="RAJASTHAN"
replace block = "DANTA RAMGARH" if block=="DANTARAMGARH" & district=="SIKAR" & state=="RAJASTHAN"
replace block = "ABU ROAD" if block=="ABU-ROAD" & district=="SIROHI" & state=="RAJASTHAN"
replace block = "NIWAI" if block=="NEWAI" & district=="TONK" & state=="RAJASTHAN"
replace block = "UNIARA" if block=="UNIYARA" & district=="TONK" & state=="RAJASTHAN"
replace block = "DHARIAWAD" if block=="DHARIYAWAD" & district=="UDAIPUR" & state=="RAJASTHAN"
replace block = "AVANASHI" if block=="AVINASHI" & district=="COIMBATORE" & state=="TAMIL NADU"
replace block = "VIRUDHACHALAM" if block=="VIRDDHACHALAM" & district=="CUDDALORE" & state=="TAMIL NADU"
replace block = "PAPPIREDDIPATTI" if block=="PAPPIREDDIPATTY" & district=="DHARMAPURI" & state=="TAMIL NADU"
replace block = "KODAIKANAL" if block=="KODIKANAL" & district=="DINDIGUL" & state=="TAMIL NADU"
replace block = "KANCHEEPURAM" if block=="KANCHIPURAM" & district=="KANCHEEPURAM" & state=="TAMIL NADU"
replace block = "MADURANTHAKAM" if block=="MADURANTHAGAM" & district=="KANCHEEPURAM" & state=="TAMIL NADU"
replace block = "SRIPERUMBUDUR" if block=="SRIPERUMBUDR" & district=="KANCHEEPURAM" & state=="TAMIL NADU"
replace block = "SRIPERUMBUDUR" if block=="SRIPERUMPUDUR" & district=="KANCHEEPURAM" & state=="TAMIL NADU"
replace block = "THOVALA" if block=="THOVALAI" & district=="KANNIYAKUMARI" & state=="TAMIL NADU"
replace block = "KILVELUR" if block=="KELVELUR" & district=="NAGAPATTINAM" & state=="TAMIL NADU"
replace block = "MAYILADUTHURAI" if block=="MAYILADUDURAI" & district=="NAGAPATTINAM" & state=="TAMIL NADU"
replace block = "AVUDAYARKOIL" if block=="AVUDAIYARKOIL" & district=="PUDUKKOTTAI" & state=="TAMIL NADU"
replace block = "TIRUVADANAI" if block=="THIRUVADANAI" & district=="RAMANATHAPURAM" & state=="TAMIL NADU"
replace block = "EDAPPADI" if block=="IDAPPADI" & district=="SALEM" & state=="TAMIL NADU"
replace block = "ILAYANGUDI" if block=="IIAYANKUDI" & district=="SIVAGANGA" & state=="TAMIL NADU"
replace block = "SIVAGANGA" if block=="SIVAGANGAI" & district=="SIVAGANGA" & state=="TAMIL NADU"
replace block = "ORATHANADU" if block=="ORATHANDU" & district=="THANJAVUR" & state=="TAMIL NADU"
replace block = "THIRUVIDAIMARUDUR" if block=="THIRUVIDAIMARUDHUR" & district=="THANJAVUR" & state=="TAMIL NADU"
replace block = "ANDIPATTI" if block=="AUNDIPATTY" & district=="THENI" & state=="TAMIL NADU"
replace block = "PALLIPATTU" if block=="PALLIPAT" & district=="THIRUVALLUR" & state=="TAMIL NADU"
replace block = "THIRUVARUR" if block=="TIRUVARUR" & district=="THIRUVARUR" & state=="TAMIL NADU"
replace block = "SATHANKULAM" if block=="SATTANKULAM" & district=="THOOTHUKKUDI" & state=="TAMIL NADU"
replace block = "THOTTIYAM" if block=="THOTTIAM" & district=="TIRUCHIRAPPALLI" & state=="TAMIL NADU"
replace block = "SANKARANKOIL" if block=="SANKARANKOVIL" & district=="TIRUNELVELI" & state=="TAMIL NADU"
replace block = "SHENKOTTAI" if block=="SHENGOTTAI" & district=="TIRUNELVELI" & state=="TAMIL NADU"
replace block = "ARANI" if block=="ARNI" & district=="TIRUVANNAMALAI" & state=="TAMIL NADU"
replace block = "ARAKONAM" if block=="ARAKKONAM" & district=="VELLORE" & state=="TAMIL NADU"
replace block = "GUDIYATHAM" if block=="GUDIYATTAM" & district=="VELLORE" & state=="TAMIL NADU"
replace block = "TIRUPATHUR" if block=="THIRUPATTUR" & district=="VELLORE" & state=="TAMIL NADU"
replace block = "KALLAKKURICHI" if block=="KALLAKURICHI" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "ARUPPUKKOTTAI" if block=="ARUPPUKOTTAI" & district=="VIRUDHUNAGAR" & state=="TAMIL NADU"
replace block = "KARIAPATTI" if block=="KARIYAPATTI" & district=="VIRUDHUNAGAR" & state=="TAMIL NADU"
replace block = "TIRUCHULI" if block=="THIRUCHULI" & district=="VIRUDHUNAGAR" & state=="TAMIL NADU"
replace block = "CHHAMANU" if block=="CHAWMANU" & district=="DHALAI" & state=="TRIPURA"
replace block = "DAMCHHARA" if block=="DAMCHERRA" & district=="NORTH TRIPURA" & state=="TRIPURA"
replace block = "PENCHARTHAL" if block=="PECHARTHAL" & district=="NORTH TRIPURA" & state=="TRIPURA"
replace block = "KARBUK" if block=="KARBOOK" & district=="SOUTH TRIPURA" & state=="TRIPURA"
replace block = "MATARBARI" if block=="MATABARI" & district=="SOUTH TRIPURA" & state=="TRIPURA"
replace block = "RUPAICHHARI" if block=="RUPAICHARI" & district=="SOUTH TRIPURA" & state=="TRIPURA"
replace block = "JAMPUIJALA" if block=="JAMPOIJALA" & district=="WEST TRIPURA" & state=="TRIPURA"
replace block = "BHIKIA SAIN" if block=="BHIKIYASAIN" & district=="ALMORA" & state=="UTTARAKHAND"
replace block = "KAPKOT" if block=="KAPKOTE" & district=="BAGESHWAR" & state=="UTTARAKHAND"
replace block = "GAIR SAIN" if block=="GAIRSAIN" & district=="CHAMOLI" & state=="UTTARAKHAND"
replace block = "KARNAPRAYAG" if block=="KARANPRAYAG" & district=="CHAMOLI" & state=="UTTARAKHAND"
replace block = "THALI SAIN" if block=="THALISAIN" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "MUNSIARI" if block=="MUNSYARI" & district=="PITHORAGARH" & state=="UTTARAKHAND"
replace block = "PURAULA" if block=="PUROLA" & district=="UTTARKASHI" & state=="UTTARAKHAND"
replace block = "GANGAJALGHATI" if block=="GANGAJAL GHATI" & district=="BANKURA" & state=="WEST BENGAL"
replace block = "INDUS" if block=="INDAS" & district=="BANKURA" & state=="WEST BENGAL"
replace block = "JAYPUR" if block=="JOYPUR" & district=="BANKURA" & state=="WEST BENGAL"
replace block = "RANIBUNDH" if block=="RANIBANDH" & district=="BANKURA" & state=="WEST BENGAL"
replace block = "KHANDAGHOSH" if block=="KHANDOGHOSH" & district=="BARDDHAMAN" & state=="WEST BENGAL"
replace block = "KHOYRASOL" if block=="KHOYRASOLE" & district=="BIRBHUM" & state=="WEST BENGAL"
replace block = "BANSIHARI" if block=="BANSHIHARI" & district=="DAKSHIN DINAJPUR" & state=="WEST BENGAL"
replace block = "HILLI" if block=="HILI" & district=="DAKSHIN DINAJPUR" & state=="WEST BENGAL"
replace block = "KUSHMUNDI" if block=="KUSHMONDI" & district=="DAKSHIN DINAJPUR" & state=="WEST BENGAL"
replace block = "BALLY JAGACHHA" if block=="BALLY JAGACHA" & district=="HAORA" & state=="WEST BENGAL"
replace block = "ARAMBAG" if block=="ARAMBAGH" & district=="HUGLI" & state=="WEST BENGAL"
replace block = "CHINSURAH MAGRA" if block=="CHINSURAH-MOGRA" & district=="HUGLI" & state=="WEST BENGAL"
replace block = "POLBA DADPUR" if block=="POLBA-DADPUR" & district=="HUGLI" & state=="WEST BENGAL"
replace block = "PURSURA" if block=="PURSURAH" & district=="HUGLI" & state=="WEST BENGAL"
replace block = "SERAMPUR UTTARPARA" if block=="SERAMPUR-UTTARPARA" & district=="HUGLI" & state=="WEST BENGAL"
replace block = "TARAKESWAR" if block=="TARAKASHWAR" & district=="HUGLI" & state=="WEST BENGAL"
replace block = "MATIALI" if block=="MATELLI" & district=="JALPAIGURI" & state=="WEST BENGAL"
replace block = "BAMANGOLA" if block=="BAMONGOLA" & district=="MALDAH" & state=="WEST BENGAL"
replace block = "NAWDA" if block=="NOWDA" & district=="MURSHIDABAD" & state=="WEST BENGAL"
replace block = "BAGMUNDI" if block=="BAGHMUNDI" & district=="PURULIYA" & state=="WEST BENGAL"
replace block = "BUNDWAN" if block=="BANDWAN" & district=="PURULIYA" & state=="WEST BENGAL"
replace block = "KALIAGANJ" if block=="KALIYAGANJ" & district=="UTTAR DINAJPUR" & state=="WEST BENGAL"
replace block = "PICHATUR" if block=="PITCHATUR" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "S.MYDUKUR" if block=="MYDUKUR" & district=="CUDDAPAH" & state=="ANDHRA PRADESH"
replace block = "ATCHAMPET" if block=="ACHAMET" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "NEKARIKALLU" if block=="NAKARIKALLU" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "ELLANTHAKUNTA" if block=="ILLANTHAKUNTA" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "PEDDAPALLE" if block=="PEDDAPALLI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "TALLADA" if block=="THALLADA" & district=="KHAMMAM" & state=="ANDHRA PRADESH"
replace block = "VANGOOR" if block=="WANGOOR" & district=="MAHBUBNAGAR" & state=="ANDHRA PRADESH"
replace block = "SHANKARAMPET (A)" if block=="SHANKARAMPET(R)" & district=="MEDAK" & state=="ANDHRA PRADESH"
replace block = "SYDAPURAM" if block=="SAIDAPURAM" & district=="NELLORE" & state=="ANDHRA PRADESH"
replace block = "YELAMANCHILI" if block=="ELAMANCHILI" & district=="WEST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "LADA" if block=="BANA" & district=="EAST KAMENG" & state=="ARUNACHAL PRADESH"
replace block = "BANSDA" if block=="VANSDA" & district=="NAVSARI" & state=="GUJARAT"
replace block = "PAKAUR" if block=="PAKUR" & district=="PAKAUR" & state=="JHARKHAND"
replace block = "KHARIBARI" if block=="KHORIBARI" & district=="DARJILING" & state=="WEST BENGAL"
replace block = "NANDA KUMAR" if block=="NANDAKUMAR" & district=="MEDINIPUR" & state=="WEST BENGAL"
replace block = "SABANG" if block=="SABONG" & district=="MEDINIPUR" & state=="WEST BENGAL"
replace block = "SAHID MATANGINI" if block=="SAHID MATANGANI" & district=="MEDINIPUR" & state=="WEST BENGAL"
replace block = "SALBANI" if block=="SALBONI" & district=="MEDINIPUR" & state=="WEST BENGAL"
replace block = "BAGDA" if block=="BAGDAH" & district=="NORTH TWENTY FOUR PARGANAS" & state=="WEST BENGAL"
replace block = "HINGALGANJ" if block=="HINGALGUNJ" & district=="NORTH TWENTY FOUR PARGANAS" & state=="WEST BENGAL"
replace block = "THAKURPUKUR MAHESTOLA" if block=="THAKURPUKUR MAHESHTALA" & district=="SOUTH TWENTY FOUR PARGANAS" & state=="WEST BENGAL"
replace block = "KADDAM (PEDDUR)" if block=="KADDAM" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "CHERUKUPALLE H/O ARUMBAKA" if block=="CHERUKUPALLE" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "SAVALYAPURAM H/O KANAMARLAPUDI" if block=="SAVALYAPURAM" & district=="GUNTUR" & state=="ANDHRA PRADESH"
replace block = "MUTHARAM (MANTHANI)" if block=="MUTHARAM MAHADEVPOOR" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "MADDIKERA (EAST)" if block=="MADDIKERA" & district=="KURNOOL" & state=="ANDHRA PRADESH"
replace block = "VISAKHAPATNAM (RURAL)" if block=="VISAKHAPATNAM URBAN" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "GHANPUR (STATION)" if block=="GHANPUR STN." & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "SIDLI (PT. I)" if block=="SIDLI" & district=="KOKRAJHAR" & state=="ASSAM"
replace block = "DHAKUAKHANA (PART I)" if block=="DHAKUAKHANA" & district=="LAKHIMPUR" & state=="ASSAM"
replace block = "TIHU" if block=="TIHU BARAMA" & district=="NALBARI" & state=="ASSAM"
replace block = "TINSUKIA" if block=="TINSUKIA URBAN" & district=="TINSUKIA" & state=="ASSAM"
replace block = "DARBHANGA" if block=="DARBHANGA URBAN" & district=="DARBHANGA" & state=="BIHAR"
replace block = "MUNGER" if block=="MUNGER SADAR" & district=="MUNGER" & state=="BIHAR"
replace block = "BARHARA" if block=="BARHARA KOTHI" & district=="PURNIA" & state=="BIHAR"
replace block = "CHAPRA" if block=="CHAPRA SADAR" & district=="SARAN" & state=="BIHAR"
replace block = "MALIA" if block=="MALIA HATINA" & district=="JUNAGADH" & state=="GUJARAT"
replace block = "BHALESSA (GANDOH)" if block=="BHALESSA" & district=="DODA" & state=="JAMMU & KASHMIR"
replace block = "GOOL GULAB GARH" if block=="GOOL" & district=="UDHAMPUR" & state=="JAMMU & KASHMIR"
replace block = "MERAL (PIPRA KALAN)" if block=="MERAL" & district=="GARHWA" & state=="JHARKHAND"
replace block = "BELGAUM" if block=="BELGAUM CITY" & district=="BELGAUM" & state=="KARNATAKA"
replace block = "MYSORE" if block=="MYSORE CITY" & district=="MYSORE" & state=="KARNATAKA"
replace block = "JABALPUR" if block=="JABALPUR (CITY)" & district=="JABALPUR" & state=="MADHYA PRADESH"
replace block = "GOTEGAON" if block=="GOTEGAON (SHRIDHAM)" & district=="NARSIMHAPUR" & state=="MADHYA PRADESH"
replace block = "AKOLA" if block=="AKOLA MC" & district=="AKOLA" & state=="MAHARASHTRA"
replace block = "DHAMANGAON RAILWAY" if block=="DHAMANGAON RLY" & district=="AMRAVATI" & state=="MAHARASHTRA"
replace block = "DESAIGANJ (VADASA)" if block=="DESAIGANJ" & district=="GADCHIROLI" & state=="MAHARASHTRA"
replace block = "ARJUNI MORGAON" if block=="ARJUNI MOR" & district=="GONDIYA" & state=="MAHARASHTRA"
replace block = "NAGPUR (RURAL)" if block=="NAGPUR (N.M.C.)" & district=="NAGPUR" & state=="MAHARASHTRA"
replace block = "NAIGAON (KHAIRGAON)" if block=="NAIGAON" & district=="NANDED" & state=="MAHARASHTRA"
replace block = "PARBHANI" if block=="PARBHANI URC" & district=="PARBHANI" & state=="MAHARASHTRA"
replace block = "KARANJA" if block=="KARANJA LAD" & district=="WASHIM" & state=="MAHARASHTRA"
replace block = "SAITU GAMPHAZOL" if block=="SAITU" & district=="SENAPATI (EXCLUDING 3 SUB-DIVISIONS)" & state=="MANIPUR"
replace block = "KAMJONG CHASSAD" if block=="KAMJONG" & district=="UKHRUL" & state=="MANIPUR"
replace block = "PHUNGYAR PHAISAT" if block=="PHUNGYAR" & district=="UKHRUL" & state=="MANIPUR"
replace block = "UKHRUL CENTRAL" if block=="UKHRUL" & district=="UKHRUL" & state=="MANIPUR"
replace block = "THINGSULTHLIAH (PART)" if block=="THINGSULTHLIAH" & district=="AIZAWL" & state=="MIZORAM"
replace block = "DIMAPUR SADAR" if block=="DIMAPUR URBAN" & district=="DIMAPUR" & state=="NAGALAND"
replace block = "KOHIMA SADAR" if block=="KOHIMA URBAN" & district=="KOHIMA" & state=="NAGALAND"
replace block = "SECHU" if block=="SECHU ZUBZA" & district=="KOHIMA" & state=="NAGALAND"
replace block = "MON SADAR" if block=="MON" & district=="MON" & state=="NAGALAND"
replace block = "PHEK SADAR" if block=="PHEK" & district=="PHEK" & state=="NAGALAND"
replace block = "TUENSANG SADAR" if block=="TUENSANG (HAUKSHANG)" & district=="TUENSANG" & state=="NAGALAND"
replace block = "WOKHA SADAR" if block=="WOKHA (URBAN)" & district=="WOKHA" & state=="NAGALAND"
replace block = "ZUNHEBOTO SADAR" if block=="ZUNHEBOTO" & district=="ZUNHEBOTO" & state=="NAGALAND"
replace block = "ZUNHEBOTO SADAR" if block=="ZUNHEBOTO URBAN" & district=="ZUNHEBOTO" & state=="NAGALAND"
replace block = "TALCHER SADAR" if block=="TALCHER MPL" & district=="ANUGUL" & state=="ORISSA"
replace block = "KANTABANJI" if block=="KANTABANJI NAC" & district=="BALANGIR" & state=="ORISSA"
replace block = "BHADRAK RURAL" if block=="BHADRAK MPL" & district=="BHADRAK" & state=="ORISSA"
replace block = "CHOUDWAR" if block=="CHOUDWAR MPL" & district=="CUTTACK" & state=="ORISSA"
replace block = "KODALA" if block=="KODALA N.A.C." & district=="GANJAM" & state=="ORISSA"
replace block = "RAMBHA" if block=="RAMBHA NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "BELPAHAR" if block=="BELPAHAR MPL" & district=="JHARSUGUDA" & state=="ORISSA"
replace block = "BRAJARAJNAGAR" if block=="BRAJARAJNAGAR MPL" & district=="JHARSUGUDA" & state=="ORISSA"
replace block = "BARBIL" if block=="BARBIL MPL" & district=="KENDUJHAR" & state=="ORISSA"
replace block = "BALUGAON" if block=="BALUGAON NAC" & district=="KHORDHA" & state=="ORISSA"
replace block = "KORAPUT TOWN" if block=="KORAPUT NAC" & district=="KORAPUT" & state=="ORISSA"
replace block = "SUNABEDA" if block=="SUNABEDA NAC" & district=="KORAPUT" & state=="ORISSA"
replace block = "BARIPADA SADAR" if block=="BARIPADA MPL" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "RAIRANGPUR TOWN" if block=="RAIRANGPUR NAC" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "KONARK" if block=="KONARK NAC" & district=="PURI" & state=="ORISSA"
replace block = "BURLA" if block=="BURLA NAC" & district=="SAMBALPUR" & state=="ORISSA"
replace block = "HIRAKUD" if block=="HIRAKUD NAC" & district=="SAMBALPUR" & state=="ORISSA"
replace block = "BIRAMITRAPUR" if block=="BIRAMITRAPUR MPL" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "SUNDARGARH TOWN" if block=="SUNDARGARH MPL" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "RAMPURA PHUL" if block=="RAMPURA" & district=="BATHINDA" & state=="PUNJAB"
replace block = "BANSWARA" if block=="BANSWARA (U)" & district=="BANSWARA" & state=="RAJASTHAN"
replace block = "BHILWARA" if block=="BHILWARA (URBAN AREA)" & district=="BHILWARA" & state=="RAJASTHAN"
replace block = "DUDU (HQ. MAUZAMABAD)" if block=="DUDU" & district=="JAIPUR" & state=="RAJASTHAN"
replace block = "JODHPUR" if block=="JODHPUR CITY" & district=="JODHPUR" & state=="RAJASTHAN"
replace block = "MERTA" if block=="MERTA CITY" & district=="NAGAUR" & state=="RAJASTHAN"
replace block = "JHADOL" if block=="JHADOL (PH)" & district=="UDAIPUR" & state=="RAJASTHAN"
replace block = "SALEM" if block=="SALEM RURAL" & district=="SALEM" & state=="TAMIL NADU"
replace block = "THANJAVUR" if block=="THANJAVUR (RURAL)" & district=="THANJAVUR" & state=="TAMIL NADU"
replace block = "KOVILPATTI" if block=="KOVILPATTI RURAL, URBAN" & district=="THOOTHUKKUDI" & state=="TAMIL NADU"
replace block = "OTTAPIDARAM" if block=="OTTAPIDARAM RURAL" & district=="THOOTHUKKUDI" & state=="TAMIL NADU"
replace block = "PALAYAMKOTTAI" if block=="PALAYAMKOTTAI RURAL" & district=="TIRUNELVELI" & state=="TAMIL NADU"
replace block = "TIRUNELVELI" if block=="TIRUNELVELI URBAN" & district=="TIRUNELVELI" & state=="TAMIL NADU"
replace block = "VELLORE" if block=="VELLORE RURAL" & district=="VELLORE" & state=="TAMIL NADU"
replace block = "HIRBANDH" if block=="HIRBANDH [KHATRA II]" & district=="BANKURA" & state=="WEST BENGAL"
replace block = "SARENGA" if block=="SARENGA [RAIPUR II]" & district=="BANKURA" & state=="WEST BENGAL"
replace block = "KURSEONG" if block=="KURSEONG TOWN" & district=="DARJILING" & state=="WEST BENGAL"
replace block = "JALPAIGURI" if block=="JALPAIGURI MUNICIPALITY" & district=="JALPAIGURI" & state=="WEST BENGAL"
replace block = "ENGLISH BAZAR" if block=="ENGLISH BAZAR(BLOCK)" & district=="MALDAH" & state=="WEST BENGAL"
replace block = "MIDNAPORE" if block=="MIDNAPORE SADAR" & district=="MEDINIPUR" & state=="WEST BENGAL"
replace block = "MURSHIDABAD JIAGANJ" if block=="MURSHIDABAD" & district=="MURSHIDABAD" & state=="WEST BENGAL"
replace block = "MUTHARAM (MAHADEVPUR)" if block=="MUTHARAM MANTHANI" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "BARIPADA TOWN" if block=="BARIPADA" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "KHALSI" if block=="KHALTSE" & district=="LEH (LADAKH)" & state=="JAMMU & KASHMIR"
replace block = "SANKU" if block=="SANKOO" & district=="KARGIL" & state=="JAMMU & KASHMIR"
replace block = "RAMSHAHR" if block=="RAM SHAHAR" & district=="SOLAN" & state=="HIMACHAL PRADESH"
replace block = "TARN TARAN" if block=="TARAN TARAN" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "PHILLAUR" if block=="PHILLOUR" & district=="JALANDHAR" & state=="PUNJAB"
replace block = "GARHSHANKAR" if block=="GARSHANKER" & district=="HOSHIARPUR" & state=="PUNJAB"
replace block = "HOSHIARPUR" if block=="HOSHIARPUR 2" & district=="HOSHIARPUR" & state=="PUNJAB"
replace block = "NAWANSHAHR" if block=="NAWAN SHAHR" & district=="NAWANSHAHR" & state=="PUNJAB"
replace block = "MOGA" if block=="MOGA 2" & district=="MOGA" & state=="PUNJAB"
replace block = "DERA BASSI" if block=="DERABASSI" & district=="PATIALA" & state=="PUNJAB"
replace block = "CHINIYALISAUR" if block=="CHINYALISAUR" & district=="UTTARKASHI" & state=="UTTARAKHAND"
replace block = "GARUD" if block=="GARUR" & district=="BAGESHWAR" & state=="UTTARAKHAND"
replace block = "BETALGHAT" if block=="BETAALGHAT" & district=="NAINITAL" & state=="UTTARAKHAND"
replace block = "BAJPUR" if block=="BAZPUR" & district=="UDHAM SINGH NAGAR" & state=="UTTARAKHAND"
replace block = "AMBALA" if block=="AMBALA 2" & district=="AMBALA" & state=="HARYANA"
replace block = "PANIPAT" if block=="PANIPAT-2" & district=="PANIPAT" & state=="HARYANA"
replace block = "NARNAUND" if block=="NARNOUND" & district=="HISAR" & state=="HARYANA"
replace block = "JHAJJAR" if block=="JHAJJAR1" & district=="JHAJJAR" & state=="HARYANA"
replace block = "MATENHAIL" if block=="MATANHAIL" & district=="JHAJJAR" & state=="HARYANA"
replace block = "FARRUKHNAGAR" if block=="FARRUK NAGAR" & district=="GURGAON" & state=="HARYANA"
replace block = "MANESAR" if block=="MANESHAR" & district=="GURGAON" & state=="HARYANA"
replace block = "GHARSANA" if block=="GHARASANA" & district=="GANGANAGAR" & state=="RAJASTHAN"
replace block = "MAHWA" if block=="MAHUWA" & district=="DAUSA" & state=="RAJASTHAN"
replace block = "RISHABHDEO" if block=="RISHABHDEV" & district=="UDAIPUR" & state=="RAJASTHAN"
replace block = "PEEPALKHOONT" if block=="PEEPALKHOOT" & district=="BANSWARA" & state=="RAJASTHAN"
replace block = "PEEPALKHOONT" if block=="PEEPALKHOOT" & district=="CHITTAURGARH" & state=="RAJASTHAN"
replace block = "GWALPARA" if block=="GWALPADA" & district=="MADHEPURA" & state=="BIHAR"
replace block = "MUSAHRI" if block=="MUSHARI" & district=="MUZAFFARPUR" & state=="BIHAR"
replace block = "DARAULI" if block=="DARAUDA" & district=="SIWAN" & state=="BIHAR"
replace block = "DESRI" if block=="DESARI" & district=="VAISHALI" & state=="BIHAR"
replace block = "BARHARA" if block=="BARAHARA" & district=="BHOJPUR" & state=="BIHAR"
replace block = "MUNGIAKUMI" if block=="MUNGIAKAMI" & district=="WEST TRIPURA" & state=="TRIPURA"
replace block = "KHATARSHNONG LAITKROH" if block=="KHADARSHNONG LAITKROH" & district=="EAST KHASI HILLS" & state=="MEGHALAYA"
replace block = "PATHARKANDI" if block=="PATHERKANDI" & district=="KARIMGANJ" & state=="ASSAM"
replace block = "MANIKCHAK" if block=="MANIKCHAWK" & district=="MALDAH" & state=="WEST BENGAL"
replace block = "HAIDERNAGAR" if block=="HAIDARNAGAR" & district=="PALAMU" & state=="JHARKHAND"
replace block = "MOHAMMAD GANJ" if block=="MOHAMMADGANJ" & district=="PALAMU" & state=="JHARKHAND"
replace block = "KANHA CHATTI" if block=="KANHACHATTI" & district=="CHATRA" & state=="JHARKHAND"
replace block = "MAYUR HAND" if block=="MAYURHAND" & district=="CHATRA" & state=="JHARKHAND"
replace block = "CHALKUSA" if block=="CHALKUSHA" & district=="HAZARIBAGH" & state=="JHARKHAND"
replace block = "CHANDWARA" if block=="CHANDWA" & district=="HAZARIBAGH" & state=="JHARKHAND"
replace block = "KATAMDAG" if block=="KATKAMDAG" & district=="HAZARIBAGH" & state=="JHARKHAND"
replace block = "TATI JHARIYA" if block=="TATIJHARIRA" & district=="HAZARIBAGH" & state=="JHARKHAND"
replace block = "PIRTANR" if block=="PIR TAND" & district=="GIRIDIH" & state=="JHARKHAND"
replace block = "SARIYA" if block=="SURIYA" & district=="GIRIDIH" & state=="JHARKHAND"
replace block = "DEVIPUR" if block=="DEVI PUR" & district=="DEOGHAR" & state=="JHARKHAND"
replace block = "MARGO MUNDA" if block=="MARGOMUNDA" & district=="DEOGHAR" & state=="JHARKHAND"
replace block = "MOHANPUR" if block=="MOHAN PUR" & district=="DEOGHAR" & state=="JHARKHAND"
replace block = "SARATH" if block=="SARTHA" & district=="DEOGHAR" & state=="JHARKHAND"
replace block = "SARWAN" if block=="SARWA" & district=="DEOGHAR" & state=="JHARKHAND"
replace block = "BASHANT RAI" if block=="BASANTRAI" & district=="GODDA" & state=="JHARKHAND"
replace block = "BOARIJOR" if block=="BOYARI JOR" & district=="GODDA" & state=="JHARKHAND"
replace block = "PURBI TUNDI" if block=="PURVI TUNDI" & district=="DHANBAD" & state=="JHARKHAND"
replace block = "TOPCHANCHI" if block=="TOPCHACHI" & district=="DHANBAD" & state=="JHARKHAND"
replace block = "HAT GAMHARIA" if block=="HATGAMHARIYA" & district=="PASHCHIMI SINGHBHUM" & state=="JHARKHAND"
replace block = "GURBANDHA" if block=="GURABANDA" & district=="PURBI SINGHBHUM" & state=="JHARKHAND"
replace block = "JHARBANDHA" if block=="JHARBANDH" & district=="BARGARH" & state=="ORISSA"
replace block = "BHOGRAI" if block=="BHOGARAI" & district=="BALESHWAR" & state=="ORISSA"
replace block = "BASUDEBPUR" if block=="BASUDEVPUR" & district=="BHADRAK" & state=="ORISSA"
replace block = "MARSAGHAI" if block=="MARSHAGHAI" & district=="KENDRAPARA" & state=="ORISSA"
replace block = "RAJNAGAR" if block=="RAJANAGAR" & district=="KENDRAPARA" & state=="ORISSA"
replace block = "DASAPALLA" if block=="DASPALLA" & district=="NAYAGARH" & state=="ORISSA"
replace block = "JATANI" if block=="JATNI" & district=="KHORDHA" & state=="ORISSA"
replace block = "ASTARANGA" if block=="ASTARANG" & district=="PURI" & state=="ORISSA"
replace block = "KRUSHNA PRASAD" if block=="KRUSHNAPRASAD" & district=="PURI" & state=="ORISSA"
replace block = "PIPILI" if block=="PIPLI" & district=="PURI" & state=="ORISSA"
replace block = "SERAGAD" if block=="SHERAGADA" & district=="GANJAM" & state=="ORISSA"
replace block = "CHAKAPADA" if block=="CHAKAPAD" & district=="KANDHAMAL" & state=="ORISSA"
replace block = "DARINGBADI" if block=="DARINGIBADI" & district=="KANDHAMAL" & state=="ORISSA"
replace block = "KOTAGARH" if block=="KOTAGHAR" & district=="KANDHAMAL" & state=="ORISSA"
replace block = "BANDHUGAON" if block=="BANDHUGAM" & district=="KORAPUT" & state=="ORISSA"
replace block = "KHADGANVA" if block=="KHADGAVA" & district=="KORIYA" & state=="CHHATTISGARH"
replace block = "BATOULI" if block=="BATAOLI" & district=="SURGUJA" & state=="CHHATTISGARH"
replace block = "OUDGI" if block=="ODGI" & district=="SURGUJA" & state=="CHHATTISGARH"
replace block = "UDAYPUR" if block=="UDAIPUR" & district=="SURGUJA" & state=="CHHATTISGARH"
replace block = "POUNDI-UPRODA" if block=="PONDI-UPRODA" & district=="KORBA" & state=="CHHATTISGARH"
replace block = "PATHARIYA" if block=="PATHARIA" & district=="BILASPUR" & state=="CHHATTISGARH"
replace block = "DURGKONDAL" if block=="DURGUKONDAL" & district=="KANKER" & state=="CHHATTISGARH"
replace block = "BADE RAJPUR" if block=="BADERAJPUR" & district=="BASTAR" & state=="CHHATTISGARH"
replace block = "BAKAVAND" if block=="BAKAWAND" & district=="BASTAR" & state=="CHHATTISGARH"
replace block = "MAKDI" if block=="MAKADI" & district=="BASTAR" & state=="CHHATTISGARH"
replace block = "BHOPALPATTANAM" if block=="BHOPAL PATTNEM" & district=="DANTEWADA" & state=="CHHATTISGARH"
replace block = "BHOPALPATTANAM" if block=="BHOPAL PATNAM" & district=="DANTEWADA" & state=="CHHATTISGARH"
replace block = "BHOPALPATTANAM" if block=="BHOPALPATNAM" & district=="DANTEWADA" & state=="CHHATTISGARH"
replace block = "BHOPALPATTANAM" if block=="BHOPALPATTNAM" & district=="DANTEWADA" & state=="CHHATTISGARH"
replace block = "USUR" if block=="USOOR" & district=="DANTEWADA" & state=="CHHATTISGARH"
replace block = "BADA-MALHERA" if block=="BADA MALEHRA" & district=="CHHATARPUR" & state=="MADHYA PRADESH"
replace block = "BADA-MALHERA" if block=="BADA MALHERA" & district=="CHHATARPUR" & state=="MADHYA PRADESH"
replace block = "MAJHGAWAN" if block=="MAJHGWAN" & district=="SATNA" & state=="MADHYA PRADESH"
replace block = "GOGAON" if block=="GOGAWAN" & district=="WEST NIMAR" & state=="MADHYA PRADESH"
replace block = "THIKRI" if block=="THIKIRI" & district=="BARWANI" & state=="MADHYA PRADESH"
replace block = "GHODA DONGRI" if block=="GHORADONGRI" & district=="BETUL" & state=="MADHYA PRADESH"
replace block = "BAHORIBAND" if block=="BAMHORIBAND" & district=="KATNI" & state=="MADHYA PRADESH"
replace block = "GHUGHARI" if block=="GHUGHRI" & district=="MANDLA" & state=="MADHYA PRADESH"
replace block = "LALBARRA" if block=="LAL BURRA" & district=="BALAGHAT" & state=="MADHYA PRADESH"
replace block = "UCHCHHAL" if block=="UCHCHAL" & district=="SURAT" & state=="GUJARAT"
replace block = "MALKAPUR" if block=="MALAKAPUR" & district=="BULDANA" & state=="MAHARASHTRA"
replace block = "MEHKAR" if block=="MEHAKAR" & district=="BULDANA" & state=="MAHARASHTRA"
replace block = "BARSHITAKLI" if block=="BARSHITAKALI" & district=="AKOLA" & state=="MAHARASHTRA"
replace block = "GHANPUR (MULUG)" if block=="GHANPUR(MULUG)" & district=="WARANGAL" & state=="ANDHRA PRADESH"
replace block = "KAKINADA (RURAL)" if block=="KAKINDA(RURAL)" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "KAKINADA RURAL" if block=="KAKINADA (RURAL)" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "KAKINADA RURAL" if block=="KAKINADA(RURAL)" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "ROWTHULAPUDI" if block=="ROWTULAPUDI" & district=="EAST GODAVARI" & state=="ANDHRA PRADESH"
replace block = "BAIREDDIPALLE" if block=="BAIREDDYPALLE" & district=="CHITTOOR" & state=="ANDHRA PRADESH"
replace block = "MADATHUKULAM" if block=="MADATHUKKULAM" & district=="COIMBATORE" & state=="TAMIL NADU"
replace block = "KADAVUR" if block=="KADAVOOR" & district=="KARUR" & state=="TAMIL NADU"
replace block = "PONNAMARAVATHI" if block=="PONNAMARAVATHY" & district=="PUDUKKOTTAI" & state=="TAMIL NADU"
replace block = "JHAJJAR" if block=="JHAJJAR2" & district=="JHAJJAR" & state=="HARYANA"
replace block = "MAYUR HAND" if block=="MAYURHUND" & district=="CHATRA" & state=="JHARKHAND"
replace block = "TATI JHARIYA" if block=="TATIJHARIYA" & district=="HAZARIBAGH" & state=="JHARKHAND"
replace block = "NAGROTA BAGWAN" if block=="NAGROTA SURIAN" & district=="KANGRA" & state=="HIMACHAL PRADESH"
replace block = "RAMPUR" if block=="RAMPUR II AT SARAHAN" & district=="SHIMLA" & state=="HIMACHAL PRADESH"
replace block = "SULTANPUR LODHI" if block=="SULTANPUR" & district=="KAPURTHALA" & state=="PUNJAB"
replace block = "GANGAPUR" if block=="GANGAPUR CITY" & district=="SAWAI MADHOPUR" & state=="RAJASTHAN"
replace block = "SANGANER" if block=="SANGANER CITY" & district=="JAIPUR" & state=="RAJASTHAN"
replace block = "NAGAUR" if block=="NAGAUR CITY" & district=="NAGAUR" & state=="RAJASTHAN"
replace block = "PHALODI" if block=="PHALODI CITY" & district=="JODHPUR" & state=="RAJASTHAN"
replace block = "HUNLI" if block=="HUNLI" & district=="LOWER DIBANG VALLEY" & state=="ARUNACHAL PRADESH"
replace block = "TUENSANG SADAR" if block=="TUENSANG" & district=="TUENSANG" & state=="NAGALAND"
replace block = "CHOKPOT" if block=="CHOKPOT BLOCK" & district=="SOUTH GARO HILLS" & state=="MEGHALAYA"
replace block = "GASUAPARA" if block=="GASUAPARA BLOCK" & district=="SOUTH GARO HILLS" & state=="MEGHALAYA"
replace block = "RONGARA" if block=="RONGARA BLOCK" & district=="SOUTH GARO HILLS" & state=="MEGHALAYA"
replace block = "MAIRANG" if block=="MAIRANG TOWN" & district=="WEST KHASI HILLS" & state=="MEGHALAYA"
replace block = "NONGSTOIN" if block=="NONGSTOIN TOWN" & district=="WEST KHASI HILLS" & state=="MEGHALAYA"
replace block = "SILCHAR" if block=="SILCHAR URBAN" & district=="CACHAR" & state=="ASSAM"
replace block = "HALDIBARI" if block=="HALDIBARI MUNICIPALITY" & district=="KOCH BIHAR" & state=="WEST BENGAL"
replace block = "RAIGANJ" if block=="RAIGANJ MUNICIPALITY" & district=="UTTAR DINAJPUR" & state=="WEST BENGAL"
replace block = "BALURGHAT" if block=="BALURGHAT MUNICIPALITY" & district=="DAKSHIN DINAJPUR" & state=="WEST BENGAL"
replace block = "SAINTHIA" if block=="SAINTHIA MUNICIPALITY" & district=="BIRBHUM" & state=="WEST BENGAL"
replace block = "JAMURIA" if block=="JAMURIA MUNICIPALITY" & district=="BARDDHAMAN" & state=="WEST BENGAL"
replace block = "RANIGANJ" if block=="RANIGANJ MUNICIPALITY" & district=="BARDDHAMAN" & state=="WEST BENGAL"
replace block = "CHAKDAH" if block=="CHAKDAH MUNI" & district=="NADIA" & state=="WEST BENGAL"
replace block = "SONAMUKHI" if block=="SONAMUKHI MUNICIPALITY" & district=="BANKURA" & state=="WEST BENGAL"
replace block = "PANSKURA" if block=="PANSKURA MUNICIPALITY" & district=="MEDINIPUR" & state=="WEST BENGAL"
replace block = "TAMLUK" if block=="TAMLUK MUNICIPALITY" & district=="MEDINIPUR" & state=="WEST BENGAL"
replace block = "BARUIPUR" if block=="BARUIPUR MUNICIPALITY" & district=="SOUTH TWENTY FOUR PARGANAS" & state=="WEST BENGAL"
replace block = "ALBERT EKKA(JARI)" if block=="ALBERT EKKA" & district=="GUMLA" & state=="JHARKHAND"
replace block = "BARGARH SADAR" if block=="BARGARH MPL" & district=="BARGARH" & state=="ORISSA"
replace block = "RAIRAKHOL" if block=="RAIRAKHOL NAC" & district=="SAMBALPUR" & state=="ORISSA"
replace block = "ANANDAPUR" if block=="ANANDAPUR MPL" & district=="KENDUJHAR" & state=="ORISSA"
replace block = "JALESWAR" if block=="JALESWAR NAC" & district=="BALESHWAR" & state=="ORISSA"
replace block = "SORO" if block=="SORO NAC" & district=="BALESHWAR" & state=="ORISSA"
replace block = "BHADRAK RURAL" if block=="BHADRAK" & district=="BHADRAK" & state=="ORISSA"
replace block = "KENDRAPARA SADAR" if block=="KENDRAPARA MUNICIPALITY" & district=="KENDRAPARA" & state=="ORISSA"
replace block = "PARADEEP LOCK" if block=="PARADEEP MPLT" & district=="JAGATSINGHAPUR" & state=="ORISSA"
replace block = "BARI RAMACHANDRAPUR" if block=="BARI" & district=="JAJAPUR" & state=="ORISSA"
replace block = "JAJPUR SADAR" if block=="JAJPUR MPL" & district=="JAJAPUR" & state=="ORISSA"
replace block = "BHUBAN" if block=="BHUBAN N.A.C." & district=="DHENKANAL" & state=="ORISSA"
replace block = "DHENKANAL SADAR" if block=="DHENKANAL MPLTY." & district=="DHENKANAL" & state=="ORISSA"
replace block = "TALCHER SADAR" if block=="TALCHER" & district=="ANUGUL" & state=="ORISSA"
replace block = "KHANDAPADA" if block=="KHANDAPADA NAC" & district=="NAYAGARH" & state=="ORISSA"
replace block = "NAYAGARH SADAR" if block=="NAYAGARH NAC" & district=="NAYAGARH" & state=="ORISSA"
replace block = "BANAPUR" if block=="BANAPUR NAC" & district=="KHORDHA" & state=="ORISSA"
replace block = "KHORDHA" if block=="KHORDHA MPL" & district=="KHORDHA" & state=="ORISSA"
replace block = "BHANJANAGAR" if block=="BHANJANAGAR NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "BUGUDA" if block=="BUGUDA NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "KABISURYANAGAR" if block=="KABISURYANAGAR NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "KODALA" if block=="KODALA NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "POLASARA" if block=="POLASARA N.A.C." & district=="GANJAM" & state=="ORISSA"
replace block = "SURADA" if block=="SURADA NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "G.UDAYAGIRI" if block=="G.UDAYAGIRI NAC" & district=="KANDHAMAL" & state=="ORISSA"
replace block = "KHARIAR" if block=="KHARIAR NAC" & district=="NUAPADA" & state=="ORISSA"
replace block = "KESINGA" if block=="KESINGA NAC" & district=="KALAHANDI" & state=="ORISSA"
replace block = "GUDARI" if block=="GUDARI NAC" & district=="RAYAGADA" & state=="ORISSA"
replace block = "RAYAGADA" if block=="RAYAGADA MPLT" & district=="RAYAGADA" & state=="ORISSA"
replace block = "JEYPUR" if block=="JEYPORE MPL" & district=="KORAPUT" & state=="ORISSA"
replace block = "JEYPUR" if block=="JEYPORE" & district=="KORAPUT" & state=="ORISSA"
replace block = "KOTPAD" if block=="KOTPAD NAC" & district=="KORAPUT" & state=="ORISSA"
replace block = "MALKANGIRI" if block=="MALKANGIRI NAC" & district=="MALKANGIRI" & state=="ORISSA"
replace block = "DABRA (PICHHORE)" if block=="DABRA" & district=="GWALIOR" & state=="MADHYA PRADESH"
replace block = "INDORE" if block=="INDORE RURAL" & district=="INDORE" & state=="MADHYA PRADESH"
replace block = "JABALPUR" if block=="JABALPUR (RURAL)" & district=="JABALPUR" & state=="MADHYA PRADESH"
replace block = "AKOLA" if block=="AKOLA PS" & district=="AKOLA" & state=="MAHARASHTRA"
replace block = "AMRAVATI" if block=="AMRAVATI MC" & district=="AMRAVATI" & state=="MAHARASHTRA"
replace block = "NAGPUR (RURAL)" if block=="NAGPUR (GRAMIN)" & district=="NAGPUR" & state=="MAHARASHTRA"
replace block = "KALYAN" if block=="KALYAN MNC" & district=="THANE" & state=="MAHARASHTRA"
replace block = "BELGAUM" if block=="BELGAUM RURAL." & district=="BELGAUM" & state=="KARNATAKA"
replace block = "DHARWAD" if block=="DHARWAD CITY" & district=="DHARWAD" & state=="KARNATAKA"
replace block = "HUBLI" if block=="HUBLI CITY" & district=="DHARWAD" & state=="KARNATAKA"
replace block = "VELLORE" if block=="VELLORE URBAN" & district=="VELLORE" & state=="TAMIL NADU"
replace block = "BHAVANI" if block=="BHAVANI SAGAR" & district=="ERODE" & state=="TAMIL NADU"
replace block = "DINDIGUL" if block=="DINDIGUL URBAN" & district=="DINDIGUL" & state=="TAMIL NADU"
replace block = "THANJAVUR" if block=="THANJAVUR (URBAN)" & district=="THANJAVUR" & state=="TAMIL NADU"
replace block = "KENDRAPARA SADAR" if block=="KENDRAPARA MPL" & district=="KENDRAPARA" & state=="ORISSA"
replace block = "JAJPUR SADAR" if block=="JAJPUR" & district=="JAJAPUR" & state=="ORISSA"
replace block = "BHUBAN" if block=="BHUBAN NAC" & district=="DHENKANAL" & state=="ORISSA"
replace block = "DHENKANAL SADAR" if block=="DHENKANAL MPL" & district=="DHENKANAL" & state=="ORISSA"
replace block = "POLASARA" if block=="POLASARA NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "KHARIAR" if block=="KHARIAR ROAD NAC" & district=="NUAPADA" & state=="ORISSA"
replace block = "INDORE" if block=="INDORE URBAN" & district=="INDORE" & state=="MADHYA PRADESH"
replace block = "JABALPUR" if block=="JABALPUR (URBAN)" & district=="JABALPUR" & state=="MADHYA PRADESH"
replace block = "AMRAVATI" if block=="AMRAVATI MNC" & district=="AMRAVATI" & state=="MAHARASHTRA"
replace block = "CHAUPARAN" if block=="CHOUPARAN" & district=="HAZARIBAGH" & state=="JHARKHAND"
replace block = "MADHUPUR" if block=="MADHU PUR" & district=="DEOGHAR" & state=="JHARKHAND"
replace block = "BANAPUR" if block=="BANPUR" & district=="KHORDHA" & state=="ORISSA"
replace block = "MAHASAMUND" if block=="MHASMUND" & district=="MAHASAMUND" & state=="CHHATTISGARH"
replace block = "MAKRANA" if block=="MAKRANA CITY" & district=="NAGAUR" & state=="RAJASTHAN"
replace block = "NAMSAI" if block=="NAMSAI CHONGKHAM" & district=="LOHIT" & state=="ARUNACHAL PRADESH"
replace block = "WOKHA SADAR" if block=="WOKHA" & district=="WOKHA" & state=="NAGALAND"
replace block = "RAJWARA" if block=="RAJWAR" & district=="KUPWARA" & state=="JAMMU & KASHMIR"
replace block = "TANGDHAR" if block=="TANGDAR" & district=="KUPWARA" & state=="JAMMU & KASHMIR"
replace block = "RUHAMA" if block=="ROHAMA" & district=="BARAMULA" & state=="JAMMU & KASHMIR"
replace block = "WAGURA" if block=="WAGOORA" & district=="BARAMULA" & state=="JAMMU & KASHMIR"
replace block = "NAGAM" if block=="MAGAM" & district=="BADGAM" & state=="JAMMU & KASHMIR"
replace block = "KAKA PORA" if block=="KAKAPORA" & district=="PULWAMA" & state=="JAMMU & KASHMIR"
replace block = "QUIMOH" if block=="QAIMOH" & district=="ANANTNAG" & state=="JAMMU & KASHMIR"
replace block = "KHAROO" if block=="KHARU" & district=="LEH (LADAKH)" & state=="JAMMU & KASHMIR"
replace block = "SHARGOL" if block=="SHARGOLE" & district=="KARGIL" & state=="JAMMU & KASHMIR"
replace block = "BHAGWA" if block=="BHAGWAH" & district=="DODA" & state=="JAMMU & KASHMIR"
replace block = "BHALLESA" if block=="BHALLA" & district=="DODA" & state=="JAMMU & KASHMIR"
replace block = "DERA" if block=="DEHRA" & district=="KANGRA" & state=="HIMACHAL PRADESH"
replace block = "LAMBAGRAON" if block=="LAMBAGAON" & district=="KANGRA" & state=="HIMACHAL PRADESH"
replace block = "NAGAR" if block=="NAGGAR" & district=="KULLU" & state=="HIMACHAL PRADESH"
replace block = "BIJHRI" if block=="BIJHARI" & district=="HAMIRPUR" & state=="HIMACHAL PRADESH"
replace block = "GAGRET" if block=="GAGRET 1" & district=="UNA" & state=="HIMACHAL PRADESH"
replace block = "DHARMPUR" if block=="DHARAMPUR" & district=="SOLAN" & state=="HIMACHAL PRADESH"
replace block = "DHARMPUR" if block=="DHRAMPUR" & district=="SOLAN" & state=="HIMACHAL PRADESH"
replace block = "KUNIHAR" if block=="KUTHAR" & district=="SOLAN" & state=="HIMACHAL PRADESH"
replace block = "CHAUHRA" if block=="CHAUHARA" & district=="SHIMLA" & state=="HIMACHAL PRADESH"
replace block = "CHAUPAL" if block=="CHOPAL" & district=="SHIMLA" & state=="HIMACHAL PRADESH"
replace block = "SRI HARGOBINDPUR" if block=="SHRI HARGOBINDPUR" & district=="GURDASPUR" & state=="PUNJAB"
replace block = "CHOLA SAHIB" if block=="CHOHLA SAHIB" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "HARSHA CHHINA" if block=="HARSA CHHINA" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "HARSHA CHHINA" if block=="HARSHAN CHHINA" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "KHADOOR SAHIB" if block=="KHADOOR SAHB" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "LOHIAN KHAS" if block=="LOHIAN KHASS" & district=="JALANDHAR" & state=="PUNJAB"
replace block = "NOOR MEHAL" if block=="NOORMAHAL" & district=="JALANDHAR" & state=="PUNJAB"
replace block = "HAZIPUR" if block=="HAJIPUR" & district=="HOSHIARPUR" & state=="PUNJAB"
replace block = "MACHHIWARA" if block=="MACCHIWARA" & district=="LUDHIANA" & state=="PUNJAB"
replace block = "DHARMKOT" if block=="DHARAMKOT" & district=="MOGA" & state=="PUNJAB"
replace block = "KOT KAPURA" if block=="KOTKAPURA" & district=="FARIDKOT" & state=="PUNJAB"
replace block = "KHERA" if block=="KHARAR" & district=="PATIALA" & state=="PUNJAB"
replace block = "AUGUST MUNI" if block=="AUGUSTYAMUNI" & district=="RUDRAPRAYAG" & state=="UTTARAKHAND"
replace block = "JAUNPUR" if block=="JOUNPUR" & district=="TEHRI GARHWAL" & state=="UTTARAKHAND"
replace block = "KIRTINAGAR" if block=="KEERTINAGAR" & district=="TEHRI GARHWAL" & state=="UTTARAKHAND"
replace block = "BIROKHAL" if block=="BIRONKHAL" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "DOGADDA" if block=="DUGADDA" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "DWARIKHAL" if block=="DWARIKAHL" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "NAUNIDANDA" if block=="NAINIDANDA" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "PABO" if block=="PABAU" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "RIKHNIKHAL" if block=="RIKHANIKHAL" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "MUNAKOT" if block=="MOONAKOT" & district=="PITHORAGARH" & state=="UTTARAKHAND"
replace block = "BHAISIYA CHHANA" if block=="BHAISIYACHANA" & district=="ALMORA" & state=="UTTARAKHAND"
replace block = "HAWAL BAGH" if block=="HAWALBAG" & district=="ALMORA" & state=="UTTARAKHAND"
replace block = "LAMGARHA" if block=="LAMGARAH" & district=="ALMORA" & state=="UTTARAKHAND"
replace block = "BHIMTAL" if block=="BHEEMTAL" & district=="NAINITAL" & state=="UTTARAKHAND"
replace block = "OKHAL KANDA" if block=="OKHALKANDA" & district=="NAINITAL" & state=="UTTARAKHAND"
replace block = "BAHADRABAD" if block=="BAHADARABAD" & district=="HARDWAR" & state=="UTTARAKHAND"
replace block = "SADAURA" if block=="SADHAURA" & district=="YAMUNANAGAR" & state=="HARYANA"
replace block = "PILLU KHERA" if block=="PILLUKHERA" & district=="JIND" & state=="HARYANA"
replace block = "SAHLAWAS" if block=="SALHAWAS" & district=="JHAJJAR" & state=="HARYANA"
replace block = "NANGAL CHAUDHRY" if block=="NANGAL CHAUDHARY" & district=="MAHENDRAGARH" & state=="HARYANA"
replace block = "NANGAL CHAUDHRY" if block=="NANGAL CHOUDHARY" & district=="MAHENDRAGARH" & state=="HARYANA"
replace block = "NIMRANA" if block=="NEEMRANA" & district=="ALWAR" & state=="RAJASTHAN"
replace block = "RENI" if block=="RAINI" & district=="ALWAR" & state=="RAJASTHAN"
replace block = "UMREN" if block=="UMRAIN" & district=="ALWAR" & state=="RAJASTHAN"
replace block = "DHOND" if block=="DHOD" & district=="SIKAR" & state=="RAJASTHAN"
replace block = "MANDOR" if block=="MANDORE" & district=="JODHPUR" & state=="RAJASTHAN"
replace block = "DHORIMANNA" if block=="DHORIMANA" & district=="BARMER" & state=="RAJASTHAN"
replace block = "SRINAGAR" if block=="SRI NAGAR" & district=="AJMER" & state=="RAJASTHAN"
replace block = "BARGAON" if block=="BADGAON" & district=="UDAIPUR" & state=="RAJASTHAN"
replace block = "BICHHIWARA" if block=="BICCHIWARA" & district=="DUNGARPUR" & state=="RAJASTHAN"
replace block = "BHAINSRORGARH" if block=="BHAINSROADGARH" & district=="CHITTAURGARH" & state=="RAJASTHAN"
replace block = "BHOPALSAGAR" if block=="BHOPAL SAGAR" & district=="CHITTAURGARH" & state=="RAJASTHAN"
replace block = "KHAIRABAD" if block=="KHERABAD" & district=="KOTA" & state=="RAJASTHAN"
replace block = "RAMLE BANGO" if block=="RAMLE-BANGGO" & district=="EAST SIANG" & state=="ARUNACHAL PRADESH"
replace block = "ANELIH-ARJU" if block=="ANELIH-ARZU" & district=="DIBANG VALLEY" & state=="ARUNACHAL PRADESH"
replace block = "PANGCHAO-WAKKA" if block=="PONGCHAU-WAKKA" & district=="TIRAP" & state=="ARUNACHAL PRADESH"
replace block = "GOSSAIGAON" if block=="GOSSAINGAON" & district=="KOKRAJHAR" & state=="ASSAM"
replace block = "MANDIA" if block=="MONDIA" & district=="BARPETA" & state=="ASSAM"
replace block = "BARIGOG-BANBHAG" if block=="BORIGOG BANBHAG" & district=="NALBARI" & state=="ASSAM"
replace block = "PUB-NALBARI" if block=="PUB NALBARI" & district=="NALBARI" & state=="ASSAM"
replace block = "BATADRAWA" if block=="BATADRAVA" & district=="NAGAON" & state=="ASSAM"
replace block = "LAOKHOWA" if block=="LAWKHOWA" & district=="NAGAON" & state=="ASSAM"
replace block = "BARBARUA" if block=="BARBARUAH" & district=="DIBRUGARH" & state=="ASSAM"
replace block = "LAHOWAL" if block=="LAHOAL" & district=="DIBRUGARH" & state=="ASSAM"
replace block = "LONGSOMEPI" if block=="LANGSOMEPI" & district=="KARBI ANGLONG" & state=="ASSAM"
replace block = "LUMBAJANG" if block=="LUMBAJONG" & district=="KARBI ANGLONG" & state=="ASSAM"
replace block = "RONGKHAG" if block=="RONGKHANG" & district=="KARBI ANGLONG" & state=="ASSAM"
replace block = "SOMELANGSO" if block=="SAMELANGSO" & district=="KARBI ANGLONG" & state=="ASSAM"
replace block = "NARSHINGPUR" if block=="NARSINGHPUR" & district=="CACHAR" & state=="ASSAM"
replace block = "RAJABAZAR" if block=="RAJA BAZAR" & district=="CACHAR" & state=="ASSAM"
replace block = "RAJBARASAMBAR" if block=="RAJBORASAMBAR" & district=="BARGARH" & state=="ORISSA"
replace block = "SOHELA" if block=="SOHELLA" & district=="BARGARH" & state=="ORISSA"
replace block = "KIRIMIRA" if block=="KIRMIRA" & district=="JHARSUGUDA" & state=="ORISSA"
replace block = "KUANRMUNDA" if block=="KUARMUNDA" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "LAHUNIPARA" if block=="LAHUNIPADA" & district=="SUNDARGARH" & state=="ORISSA"
replace block = "BARSAHI" if block=="BARASAHI" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "SHAMAKHUNTA" if block=="SAMAKHUNTA" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "SUKRULI" if block=="SUKURULI" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "SIMILIA" if block=="SIMULIA" & district=="BALESHWAR" & state=="ORISSA"
replace block = "GARADPUR" if block=="GARADAPUR" & district=="KENDRAPARA" & state=="ORISSA"
replace block = "KANTAPADA" if block=="KANTAPARA" & district=="CUTTACK" & state=="ORISSA"
replace block = "BADACHANA" if block=="BARCHANA" & district=="JAJAPUR" & state=="ORISSA"
replace block = "JAGANNATHPRASAD" if block=="JAGANATHPRASAD" & district=="GANJAM" & state=="ORISSA"
replace block = "GUMA" if block=="GUMMA" & district=="GAJAPATI" & state=="ORISSA"
replace block = "PHULABANI" if block=="PHULBANI" & district=="KANDHAMAL" & state=="ORISSA"
replace block = "BAUDH" if block=="BOUDH" & district=="BAUDH" & state=="ORISSA"
replace block = "RAMANGUDA" if block=="RAMANAGUDA" & district=="RAYAGADA" & state=="ORISSA"
replace block = "KHAIRAPUT" if block=="KHAIRPUT" & district=="MALKANGIRI" & state=="ORISSA"
replace block = "KORKUNDA" if block=="KORUKONDA" & district=="MALKANGIRI" & state=="ORISSA"
replace block = "KUDUMULGUM" if block=="KUDUMULUGUMA" & district=="MALKANGIRI" & state=="ORISSA"
replace block = "GARIABAND" if block=="GARIYABAND" & district=="RAIPUR" & state=="CHHATTISGARH"
replace block = "PAHADGARH" if block=="PAHARGARH" & district=="MORENA" & state=="MADHYA PRADESH"
replace block = "GANGEV" if block=="GANGEO" & district=="REWA" & state=="MADHYA PRADESH"
replace block = "KATTIWADA" if block=="KATTHIWARA" & district=="JHABUA" & state=="MADHYA PRADESH"
replace block = "UDAIGARH" if block=="UDAYGARH" & district=="JHABUA" & state=="MADHYA PRADESH"
replace block = "BALDI" if block=="BALADI" & district=="EAST NIMAR" & state=="MADHYA PRADESH"
replace block = "BHIMPURA" if block=="BHIMPUR" & district=="BETUL" & state=="MADHYA PRADESH"
replace block = "BAJANG" if block=="BAJAG" & district=="DINDORI" & state=="MADHYA PRADESH"
replace block = "KARANJIYA" if block=="KARANJIA" & district=="DINDORI" & state=="MADHYA PRADESH"
replace block = "MENHADWANI" if block=="MEHANDWANI" & district=="DINDORI" & state=="MADHYA PRADESH"
replace block = "BIJADANDI" if block=="BEEJADANDI" & district=="MANDLA" & state=="MADHYA PRADESH"
replace block = "YELLAREDDIPET" if block=="YELLAREDDYPET" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "JAGALUR" if block=="JAGALOOR" & district=="DAVANAGERE" & state=="KARNATAKA"
replace block = "AREEKODE" if block=="AREACODE" & district=="MALAPPURAM" & state=="KERALA"
replace block = "KUTTIPPURAM" if block=="KUTTIPURAM" & district=="MALAPPURAM" & state=="KERALA"
replace block = "ADIMALI" if block=="ADIMALY" & district=="IDUKKI" & state=="KERALA"
replace block = "KADAMBATTUR" if block=="KADAMBATHUR" & district=="THIRUVALLUR" & state=="TAMIL NADU"
replace block = "TIRUVELANGADU" if block=="THIRUVALANGADU" & district=="THIRUVALLUR" & state=="TAMIL NADU"
replace block = "KATTANKOLATTUR" if block=="KATTANKOLATHUR" & district=="KANCHEEPURAM" & state=="TAMIL NADU"
replace block = "K.V. KUPPAM" if block=="K V KUPPAM" & district=="VELLORE" & state=="TAMIL NADU"
replace block = "KANDILI" if block=="KANDHILI" & district=="VELLORE" & state=="TAMIL NADU"
replace block = "TIMIRI" if block=="THIMIRI" & district=="VELLORE" & state=="TAMIL NADU"
replace block = "KAVERIPATTINAM" if block=="KAVERIPATINAM" & district=="DHARMAPURI" & state=="TAMIL NADU"
replace block = "THALY" if block=="THALLY" & district=="DHARMAPURI" & state=="TAMIL NADU"
replace block = "ANAKAVUR" if block=="ANAKKAVUR" & district=="TIRUVANNAMALAI" & state=="TAMIL NADU"
replace block = "JAWATHU HILLS" if block=="JAWADHU HILLS" & district=="TIRUVANNAMALAI" & state=="TAMIL NADU"
replace block = "KILPERNNATHUR" if block=="KILPENNATHUR" & district=="TIRUVANNAMALAI" & state=="TAMIL NADU"
replace block = "PERANAMALLUR" if block=="PERNAMALLUR" & district=="TIRUVANNAMALAI" & state=="TAMIL NADU"
replace block = "WEST ARANI" if block=="WEST ARNI" & district=="TIRUVANNAMALAI" & state=="TAMIL NADU"
replace block = "CHINNA SALEM" if block=="CHINNASALEM" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "RISHIVANDIYAM" if block=="RISHIVANTHIYAM" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "VIRKRAVANDI" if block=="VIKARAVANDI" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "AYODHIAPATTINAM" if block=="AYOTHIYAPATTINAM" & district=="SALEM" & state=="TAMIL NADU"
replace block = "KADAYAMPATTI" if block=="KADAYAMPATTY" & district=="SALEM" & state=="TAMIL NADU"
replace block = "PANAIMARATHUPATTI" if block=="PANAMARATHUPATTY" & district=="SALEM" & state=="TAMIL NADU"
replace block = "TALAVASAL" if block=="THALAIVASAL" & district=="SALEM" & state=="TAMIL NADU"
replace block = "ELAICHIPALAYAM" if block=="ELACHIPALAYAM" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "ERUMAIPATTI" if block=="ERUMAPATTI" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "KABILAMALAI" if block=="KABILARMALAI" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "KOLLI HILLS" if block=="KOLLIHILLS" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "PARAMATHI" if block=="PARAMATHY" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "PUDUCHATRAM" if block=="PUDUCHADRAM" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "VENNANTHUR" if block=="VENNANDUR" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "TALAVADI" if block=="THALAVADY" & district=="ERODE" & state=="TAMIL NADU"
replace block = "VELLAKOIL" if block=="VELLOKOIL" & district=="ERODE" & state=="TAMIL NADU"
replace block = "KINATHUKADAVU" if block=="KINATHUKKADAVU" & district=="COIMBATORE" & state=="TAMIL NADU"
replace block = "GUZILIAMPARAI" if block=="GUJILIAMPARAI" & district=="DINDIGUL" & state=="TAMIL NADU"
replace block = "SHANARPATTI" if block=="SANARPATTY" & district=="DINDIGUL" & state=="TAMIL NADU"
replace block = "THOPPAMPATTI" if block=="THOPPAMPATTY" & district=="DINDIGUL" & state=="TAMIL NADU"
replace block = "K.PARAMATHY" if block=="K.PARAMATHI" & district=="KARUR" & state=="TAMIL NADU"
replace block = "MANACHANALLUR" if block=="MANNACHANNALLUR" & district=="TIRUCHIRAPPALLI" & state=="TAMIL NADU"
replace block = "PULLAMPADI" if block=="PULLAMBADI" & district=="TIRUCHIRAPPALLI" & state=="TAMIL NADU"
replace block = "UPPILIYAPURAM" if block=="UPPILIAPURAM" & district=="TIRUCHIRAPPALLI" & state=="TAMIL NADU"
replace block = "VAIYAMPATTI" if block=="VAIYAMPATTY" & district=="TIRUCHIRAPPALLI" & state=="TAMIL NADU"
replace block = "KOMARATCHI" if block=="KUMARATCHI" & district=="CUDDALORE" & state=="TAMIL NADU"
replace block = "MANGALUR" if block=="MANGALORE" & district=="CUDDALORE" & state=="TAMIL NADU"
replace block = "KEELAIYUR" if block=="KEEZHAIYUR" & district=="NAGAPATTINAM" & state=="TAMIL NADU"
replace block = "KORADACHERI" if block=="KORADACHERY" & district=="THIRUVARUR" & state=="TAMIL NADU"
replace block = "SETHUBHAVACHATRAM" if block=="SETHUBAVACHATRAM" & district=="THANJAVUR" & state=="TAMIL NADU"
replace block = "KUNNANDARKOVIL" if block=="KUNNANDARKOIL" & district=="PUDUKKOTTAI" & state=="TAMIL NADU"
replace block = "TIRUVARANKULAM" if block=="THIRUVARANKULAM" & district=="PUDUKKOTTAI" & state=="TAMIL NADU"
replace block = "KANNANKUDI" if block=="KANNANGUDI" & district=="SIVAGANGA" & state=="TAMIL NADU"
replace block = "S. PUDUR" if block=="S.PUDUR" & district=="SIVAGANGA" & state=="TAMIL NADU"
replace block = "SINGAMPUNERI" if block=="SINGAMPUNARI" & district=="SIVAGANGA" & state=="TAMIL NADU"
replace block = "THIRUPUVANAM" if block=="THIRUPPUVANAM" & district=="SIVAGANGA" & state=="TAMIL NADU"
replace block = "KALLLIKUDI" if block=="KALLIKUDI" & district=="MADURAI" & state=="TAMIL NADU"
replace block = "THIRUPARANKUNDRAM" if block=="THIRUPARAMKUNDRAM" & district=="MADURAI" & state=="TAMIL NADU"
replace block = "TIRUPULLANI" if block=="THIRUPPULLANI" & district=="RAMANATHAPURAM" & state=="TAMIL NADU"
replace block = "ALWARTHIRUNAGIRI" if block=="ALWARTHIRUNAGARI" & district=="THOOTHUKKUDI" & state=="TAMIL NADU"
replace block = "KARUNKULAM" if block=="KARUNGULAM" & district=="THOOTHUKKUDI" & state=="TAMIL NADU"
replace block = "KAYATHARU" if block=="KAYATHAR" & district=="THOOTHUKKUDI" & state=="TAMIL NADU"
replace block = "UDANGUDI" if block=="UDANGUDY" & district=="THOOTHUKKUDI" & state=="TAMIL NADU"
replace block = "KILLIYUR" if block=="KILLIYOOR" & district=="KANNIYAKUMARI" & state=="TAMIL NADU"
replace block = "MUNCHIRA" if block=="MUNCHIRAI" & district=="KANNIYAKUMARI" & state=="TAMIL NADU"
replace block = "THIRUVATTARU" if block=="THIRUVATTAR" & district=="KANNIYAKUMARI" & state=="TAMIL NADU"
replace block = "SRI HARGOBINDPUR" if block=="SHRI HARGOBIND PUR" & district=="GURDASPUR" & state=="PUNJAB"
replace block = "SADAURA" if block=="SADHOURA" & district=="YAMUNANAGAR" & state=="HARYANA"
replace block = "ANDANALLUR" if block=="ANDHANALLUR" & district=="TIRUCHIRAPPALLI" & state=="TAMIL NADU"
replace block = "LOHIAN KHAS" if block=="LOHIAN" & district=="JALANDHAR" & state=="PUNJAB"
replace block = "NISSING AT CHIRAO" if block=="NISSING" & district=="KARNAL" & state=="HARYANA"
replace block = "BHATTU KALAN" if block=="BHATTU" & district=="FATEHABAD" & state=="HARYANA"
replace block = "ATELI NANGAL" if block=="ATELI" & district=="MAHENDRAGARH" & state=="HARYANA"
replace block = "KHOL AT REWARI" if block=="KHOL" & district=="REWARI" & state=="HARYANA"
replace block = "SAMBHAR" if block=="SAMBHAR LAKE" & district=="JAIPUR" & state=="RAJASTHAN"
replace block = "BAKANI FOREST VILLAGE" if block=="BAKANI" & district=="JHALAWAR" & state=="RAJASTHAN"
replace block = "KANGPOKPI T.D. BLOCK" if block=="KANGPOKPI" & district=="SENAPATI (EXCLUDING 3 SUB-DIVISIONS)" & state=="MANIPUR"
replace block = "SAIKUL T. D. BLOCK" if block=="SAIKUL" & district=="SENAPATI (EXCLUDING 3 SUB-DIVISIONS)" & state=="MANIPUR"
replace block = "TAMEI T.D.BLOCK" if block=="TAMEI" & district=="TAMENGLONG" & state=="MANIPUR"
replace block = "TOUSEM T.D. BLOCK" if block=="TOUSEM" & district=="TAMENGLONG" & state=="MANIPUR"
replace block = "CHINGAI T.D.BLOCK" if block=="CHINGAI" & district=="UKHRUL" & state=="MANIPUR"
replace block = "KASOM KHULLEN T.D.BLOCK" if block=="KASOM" & district=="UKHRUL" & state=="MANIPUR"
replace block = "KASOM KHULLEN T.D.BLOCK" if block=="KASOM KL." & district=="UKHRUL" & state=="MANIPUR"
replace block = "KAPILI PT." if block=="KAPILI" & district=="MARIGAON" & state=="ASSAM"
replace block = "KAPILI PT." if block=="KAPILI" & district=="NAGAON" & state=="ASSAM"
replace block = "SANTIPUR" if block=="SANTIPUR MUNI" & district=="NADIA" & state=="WEST BENGAL"
replace block = "SAMBALPUR (DHANKAUDA)" if block=="SAMBALPUR MPL" & district=="SAMBALPUR" & state=="ORISSA"
replace block = "KARANJIA" if block=="KARANJIA NAC" & district=="MAYURBHANJ" & state=="ORISSA"
replace block = "PATTAMUNDAI" if block=="PATTAMUNDAI NAC" & district=="KENDRAPARA" & state=="ORISSA"
replace block = "BELLAGUNTHA" if block=="BELLAGUNTHA NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "GANJAM" if block=="GANJAM NAC" & district=="GANJAM" & state=="ORISSA"
replace block = "BHAWANIPATNA" if block=="BHAWANIPATNA MPL" & district=="KALAHANDI" & state=="ORISSA"
replace block = "JUNAGARH" if block=="JUNAGARH NAC" & district=="KALAHANDI" & state=="ORISSA"
replace block = "ST. THOMAS MOUNT" if block=="ST. THOMAS MOUNT (RURAL)" & district=="KANCHEEPURAM" & state=="TAMIL NADU"
replace block = "T. KALLUPATTI" if block=="T. VADIPATTI" & district=="MADURAI" & state=="TAMIL NADU"
replace block = "MOGA" if block=="MOGA-2" & district=="MOGA" & state=="PUNJAB"
replace block = "ZIRO (SADAR)" if block=="ZIRO I C.D. BLOCK" & district=="LOWER SUBANSIRI" & state=="ARUNACHAL PRADESH"
replace block = "THE DANGS" if block=="AHWA" & district=="THE DANGS" & state=="GUJARAT"
replace block = "KUCHAMAN CITY" if block=="KUCHAMAN" & district=="NAGAUR" & state=="RAJASTHAN"
replace block = "MUNCHINGI PUTTU" if block=="MUNCHINGPUT" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "RAISEN" if block=="SANCHI" & district=="RAISEN" & state=="MADHYA PRADESH"
replace block = "GOHARGANJ" if block=="OBEDULLAGANJ" & district=="RAISEN" & state=="MADHYA PRADESH"
replace block = "DIDWANA" if block=="DEEDWANA" & district=="NAGAUR" & state=="RAJASTHAN"
replace block = "KENDUJHARGARH" if block=="KEONJHAR" & district=="KENDUJHAR" & state=="ORISSA"
replace block = "BAYTOO" if block=="BAITU" & district=="BARMER" & state=="RAJASTHAN"
replace block = "DOD BALLAPUR" if block=="DODDABALLAPURA" & district=="BANGALORE RURAL" & state=="KARNATAKA"
replace block = "BAIDHAN" if block=="WAIDHAN" & district=="SIDHI" & state=="MADHYA PRADESH"
replace block = "RUPNAGAR" if block=="ROPAR" & district=="RUPNAGAR" & state=="PUNJAB"
replace block = "TAMAR I" if block=="TAMAR" & district=="RANCHI" & state=="JHARKHAND"
replace block = "GHANSAUR" if block=="GHANSORE" & district=="SEONI" & state=="MADHYA PRADESH"
replace block = "PIRAWA" if block=="SUNEL" & district=="JHALAWAR" & state=="RAJASTHAN"
replace block = "NARSIMHAPUR" if block=="NARSINGHPUR" & district=="NARSIMHAPUR" & state=="MADHYA PRADESH"
replace block = "GUMMALAKSHMIPURAM" if block=="G.L.PURAM" & district=="VIZIANAGARAM" & state=="ANDHRA PRADESH"
replace block = "GUDEM KOTHA VEEDHI" if block=="G.K.VEEDHI" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "JHAGADIA" if block=="ZAGHADIA" & district=="BHARUCH" & state=="GUJARAT"
replace block = "MADANPUR RAMPUR" if block=="M.RAMPUR" & district=="KALAHANDI" & state=="ORISSA"
replace block = "SIDHAW" if block=="BAGAHA II (SIDHAW)" & district=="PASHCHIM CHAMPARAN" & state=="BIHAR"
replace block = "ARSIKERE" if block=="ARASIKERE" & district=="HASSAN" & state=="KARNATAKA"
replace block = "CHHURIA" if block=="CHURIA" & district=="RAJNANDGAON" & state=="CHHATTISGARH"
replace block = "CHHURIYA" if block=="CHHURIA" & district=="RAJNANDGAON" & state=="CHHATTISGARH"
replace block = "PUSOUR" if block=="PUSSORE" & district=="RAIGARH" & state=="CHHATTISGARH"
replace block = "DAMBO RONGJENG" if block=="RONGJENG" & district=="EAST GARO HILLS" & state=="MEGHALAYA"
replace block = "THUAMUL RAMPUR" if block=="TH RAMPUR" & district=="KALAHANDI" & state=="ORISSA"
replace block = "KALYANASINGPUR" if block=="K.SINGPUR" & district=="RAYAGADA" & state=="ORISSA"
replace block = "GANGANAGAR" if block=="SRI GANGANAGAR" & district=="GANGANAGAR" & state=="RAJASTHAN"
replace block = "ARKALGUD" if block=="ARAKALAGUDU" & district=="HASSAN" & state=="KARNATAKA"
replace block = "JAHAZPUR" if block=="JAHAJPUR" & district=="BHILWARA" & state=="RAJASTHAN"
replace block = "CHHOTA UDAIPUR" if block=="CHHOTA-UDEPUR" & district=="VADODARA" & state=="GUJARAT"
replace block = "DONDI LUHARA" if block=="DAUNDI LOHARA" & district=="DURG" & state=="CHHATTISGARH"
replace block = "ASIND" if block=="AASIND" & district=="BHILWARA" & state=="RAJASTHAN"
replace block = "GADARWARA" if block=="SAIKHEDA" & district=="NARSIMHAPUR" & state=="MADHYA PRADESH"
replace block = "BISHAMAKATAK" if block=="BISSAMCUTTACK" & district=="RAYAGADA" & state=="ORISSA"
replace block = "SATNA (SOHAWAL)" if block=="SOHAWAL" & district=="SATNA" & state=="MADHYA PRADESH"
replace block = "CHHUIKHADAN" if block=="CHUIKHADAN" & district=="RAJNANDGAON" & state=="CHHATTISGARH"
replace block = "JHUNJHUNUN" if block=="JHUNJHUNU" & district=="JHUNJHUNUN" & state=="RAJASTHAN"
replace block = "MERTA" if block=="MERTACITY" & district=="NAGAUR" & state=="RAJASTHAN"
replace block = "ERKI (TAMAR II)" if block=="ARKI" & district=="RANCHI" & state=="JHARKHAND"
replace block = "SEONI-MALWA" if block=="SIVNI MAALVA" & district=="HOSHANGABAD" & state=="MADHYA PRADESH"
replace block = "SAKLESHPUR" if block=="SAKALESHAPURA" & district=="HASSAN" & state=="KARNATAKA"
replace block = "BAGAHA" if block=="BAGAHA I" & district=="PASHCHIM CHAMPARAN" & state=="BIHAR"
replace block = "DASADA" if block=="PATDI DASADA" & district=="SURENDRANAGAR" & state=="GUJARAT"
replace block = "PARBHANI" if block=="PARHBANI" & district=="PARBHANI" & state=="MAHARASHTRA"
replace block = "BADAMBA" if block=="BARAMBA" & district=="CUTTACK" & state=="ORISSA"
replace block = "BOLAGAD" if block=="BOLGARH" & district=="KHORDHA" & state=="ORISSA"
replace block = "UMARGA" if block=="OMERGA" & district=="OSMANABAD" & state=="MAHARASHTRA"
replace block = "TITLAGARH" if block=="TITILAGARH" & district=="BALANGIR" & state=="ORISSA"
replace block = "LACHHMANGARH" if block=="LAXMANGARH" & district=="SIKAR" & state=="RAJASTHAN"
replace block = "MADANPUR RAMPUR" if block=="M. RAMPUR" & district=="KALAHANDI" & state=="ORISSA"
replace block = "MANJLEGAON" if block=="MAJALGAON" & district=="BID" & state=="MAHARASHTRA"
replace block = "BALESHWAR SADAR" if block=="SADAR" & district=="BALESHWAR" & state=="ORISSA"
replace block = "CHACHAURA" if block=="CHACHODA" & district=="GUNA" & state=="MADHYA PRADESH"
replace block = "DONDI" if block=="DAUNDI" & district=="DURG" & state=="CHHATTISGARH"
replace block = "BARAPALI" if block=="BARPALI" & district=="BARGARH" & state=="ORISSA"
replace block = "PURUSOTTAMPUR" if block=="PURUSOTAMPUR" & district=="GANJAM" & state=="ORISSA"
replace block = "ATHMALLIK" if block=="ATHAMALLIK" & district=="ANUGUL" & state=="ORISSA"
replace block = "CHAKIA(PIPRA)" if block=="CHAKIA" & district=="PURBA CHAMPARAN" & state=="BIHAR"
replace block = "RUPBAS" if block=="ROOPWAS" & district=="BHARATPUR" & state=="RAJASTHAN"
replace block = "DARBHANGA" if block=="DARBHANGA-RURAL" & district=="DARBHANGA" & state=="BIHAR"
replace block = "LAKSHMIPUR" if block=="LAXMIPUR" & district=="KORAPUT" & state=="ORISSA"
replace block = "PALARI" if block=="PLARI" & district=="RAIPUR" & state=="CHHATTISGARH"
replace block = "THUAMUL RAMPUR" if block=="TH. RAMPUR" & district=="KALAHANDI" & state=="ORISSA"
replace block = "KANALI CHHINA" if block=="KANALICHHEENA" & district=="PITHORAGARH" & state=="UTTARAKHAND"
replace block = "JAMAI" if block=="JUNNARDEO" & district=="CHHINDWARA" & state=="MADHYA PRADESH"
replace block = "GADARWARA" if block=="CHICHLI" & district=="NARSIMHAPUR" & state=="MADHYA PRADESH"
replace block = "CHHATARPUR" if block=="ISHANAGAAR" & district=="CHHATARPUR" & state=="MADHYA PRADESH"
replace block = "BANSWARA" if block=="TALWARA" & district=="BANSWARA" & state=="RAJASTHAN"
replace block = "TUSHURA" if block=="GUDVELA" & district=="BALANGIR" & state=="ORISSA"
replace block = "AKRANI" if block=="DHADGAON" & district=="NANDURBAR" & state=="MAHARASHTRA"
replace block = "RAMANUJGANJ" if block=="RAMCHANDRAPUR" & district=="SURGUJA" & state=="CHHATTISGARH"
replace block = "HUZUR" if block=="PHANDA" & district=="BHOPAL" & state=="MADHYA PRADESH"
replace block = "HUZUR" if block=="PHANDA RURAL" & district=="BHOPAL" & state=="MADHYA PRADESH"
replace block = "SOHAGPUR" if block=="GOHPARU" & district=="SHAHDOL" & state=="MADHYA PRADESH"
replace block = "KELAPUR" if block=="PANDHARKAWADA" & district=="YAVATMAL" & state=="MAHARASHTRA"
replace block = "GIRD" if block=="MORAR(RURAL)" & district=="GWALIOR" & state=="MADHYA PRADESH"
replace block = "CHURACHANDPUR NORTH" if block=="HENGLEP" & district=="CHURACHANDPUR" & state=="MANIPUR"
replace block = "RAJIM" if block=="FINGESWAR" & district=="RAIPUR" & state=="CHHATTISGARH"
replace block = "GAURIHAR" if block=="BARIGARH" & district=="CHHATARPUR" & state=="MADHYA PRADESH"
replace block = "SUPA" if block=="JOIDA" & district=="UTTARA KANNADA" & state=="KARNATAKA"
replace block = "ITARSI" if block=="KESLA" & district=="HOSHANGABAD" & state=="MADHYA PRADESH"
replace block = "SAMPGAON" if block=="BAILHONGAL" & district=="BELGAUM" & state=="KARNATAKA"
replace block = "ZARI-JAMANI" if block=="ZARI" & district=="YAVATMAL" & state=="MAHARASHTRA"
replace block = "ULUNDURPETTAI" if block=="ULUNDURPET" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "KUNDAPURA" if block=="KUNDAPUR" & district=="UDUPI" & state=="KARNATAKA"
replace block = "NIRSA-CUM-CHIRKUNDA" if block=="NIRSA" & district=="DHANBAD" & state=="JHARKHAND"
replace block = "TRIMBAKESHWAR" if block=="TRIMBAK" & district=="NASHIK" & state=="MAHARASHTRA"
replace block = "BAGHMARA-CUM-KATRAS" if block=="BAGHMARA" & district=="DHANBAD" & state=="JHARKHAND"
replace block = "KASHINAGARA" if block=="KASHINAGAR" & district=="GAJAPATI" & state=="ORISSA"
replace block = "GOBICHETTIPALAYAM" if block=="GOBI" & district=="ERODE" & state=="TAMIL NADU"
replace block = "DHANBAD-CUM-KENDUADIH-CUM-JAGTA" if block=="DHANBAD" & district=="DHANBAD" & state=="JHARKHAND"
replace block = "KHAGAM-MIAO" if block=="KHAGAM" & district=="CHANGLANG" & state=="ARUNACHAL PRADESH"
replace block = "PURNIA EAST" if block=="PURNIA" & district=="PURNIA" & state=="BIHAR"
replace block = "SATHYAMANGALAM" if block=="SATHY" & district=="ERODE" & state=="TAMIL NADU"
replace block = "BASSI PATHANA" if block=="BASSI" & district=="FATEHGARH SAHIB" & state=="PUNJAB"
replace block = "JAMPUII HILLS" if block=="JAMPUI" & district=="NORTH TRIPURA" & state=="TRIPURA"
replace block = "KEOTIRANWAY" if block=="KEOTI" & district=="DARBHANGA" & state=="BIHAR"
replace block = "MEDIPALLE" if block=="MEDIPALLY" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "MADUGULA" if block=="V.MADUGULA" & district=="VISAKHAPATNAM" & state=="ANDHRA PRADESH"
replace block = "DONDILUHARA" if block=="DONDI LUHARA" & district=="DURG" & state=="CHHATTISGARH"
replace block = "ENGLISH BAZAR" if block=="ENGLISH BAZAR()" & district=="MALDAH" & state=="WEST BENGAL"
replace block = "SHIRUR (KASAR)" if block=="SHIRUR" & district=="BID" & state=="MAHARASHTRA"
replace block = "BAUDH SADAR" if block=="BAUDH" & district=="BAUDH" & state=="ORISSA"
replace block = "PARADIP" if block=="PARADIP MPTL" & district=="JAGATSINGHAPUR" & state=="ORISSA"
replace block = "NAWA" if block=="NAWA CITY" & district=="NAGAUR" & state=="RAJASTHAN"
replace block = "SIKAR" if block=="SIKAR SHAHAE" & district=="SIKAR" & state=="RAJASTHAN"
replace block = "JOREBUNGLOW SUKIAPOKHRI" if block=="JOREBUNGLOW SUKHIA" & district=="DARJILING" & state=="WEST BENGAL"
replace block = "JAGADHRI" if block=="JAGADHARI" & district=="YAMUNANAGAR" & state=="HARYANA"
replace block = "SAHARA" if block=="SAHADA" & district=="BHILWARA" & state=="RAJASTHAN"
replace block = "ATHIBUNG" if block=="AHTHIBUNG" & district=="KOHIMA" & state=="NAGALAND"
replace block = "GIDHAUR" if block=="GIDHOUR" & district=="CHATRA" & state=="JHARKHAND"
replace block = "LITIPARA" if block=="LITTIPARA" & district=="PAKAUR" & state=="JHARKHAND"
replace block = "BAGBAHRA" if block=="BAGBAHARA" & district=="MAHASAMUND" & state=="CHHATTISGARH"
replace block = "BHIMINI" if block=="BHEEMINI" & district=="ADILABAD" & state=="ANDHRA PRADESH"
replace block = "MALHARRAO" if block=="MALHAR RAO" & district=="KARIMNAGAR" & state=="ANDHRA PRADESH"
replace block = "SHAHZADPUR" if block=="SHEHZADPUR" & district=="AMBALA" & state=="HARYANA"
replace block = "GUNDLA PALLE" if block=="GUNDLAPALLY" & district=="NALGONDA" & state=="ANDHRA PRADESH"
replace block = "BARKOT" if block=="BARKOTE" & district=="DEBAGARH" & state=="ORISSA"
replace block = "BURWAN" if block=="BARWAN" & district=="MURSHIDABAD" & state=="WEST BENGAL"		
replace block = "KENDUJHAR SADAR" if block=="KENDUJHARGARH" & district=="KENDUJHAR" & state=="ORISSA"
replace block = "KRISHNARAJANAGARA" if block=="K.R.NAGARA" & district=="MYSORE" & state=="KARNATAKA"
replace block = "ZIRO" if block=="ZIRO I" & district=="LOWER SUBANSIRI" & state=="ARUNACHAL PRADESH"
replace block = "HEGGADADEVANKOTE" if block=="H.D.KOTE" & district=="MYSORE" & state=="KARNATAKA"
replace block = "PARASGAD" if block=="SOUNDATTI" & district=="BELGAUM" & state=="KARNATAKA"
replace block = "DAVANAGERE" if block=="DAVANAGERE(N)" & district=="DAVANAGERE" & state=="KARNATAKA"
replace block = "PITHORAGARH" if block=="BIN" & district=="PITHORAGARH" & state=="UTTARAKHAND"
replace block = "ATHAGAD" if block=="ATHGARH" & district=="CUTTACK" & state=="ORISSA"
replace block = "CHANDURBAZAR" if block=="CHANDUR BZ" & district=="AMRAVATI" & state=="MAHARASHTRA"
replace block = "MALERKOTLA" if block=="AHMEDGARH" & district=="SANGRUR" & state=="PUNJAB"
replace block = "CHANDIA" if block=="KARKELI" & district=="UMARIA" & state=="MADHYA PRADESH"
replace block = "ANUGUL" if block=="ANGUL" & district=="ANUGUL" & state=="ORISSA"
replace block = "NANDGAON-KHANDESHWAR" if block=="NANDGAON KH." & district=="AMRAVATI" & state=="MAHARASHTRA"
replace block = "SIRPUR (T)" if block=="SIRPUR" & district=="ADILABAD" & state=="ANDHRA PRADESH"

	// based on VD 2011 BLOCK2 names!
replace block = "LANGET" if block=="LANGATE" & district=="KUPWARA" & state=="JAMMU & KASHMIR"
replace block = "RAJWAR" if block=="RAJWARA" & district=="KUPWARA" & state=="JAMMU & KASHMIR"
replace block = "TANGHDAR" if block=="TANGDHAR" & district=="KUPWARA" & state=="JAMMU & KASHMIR"
replace block = "HAJAN" if block=="HAJIN" & district=="BARAMULA" & state=="JAMMU & KASHMIR"
replace block = "KUNZER" if block=="KUNZAR" & district=="BARAMULA" & state=="JAMMU & KASHMIR"
replace block = "ROHAMA" if block=="RUHAMA" & district=="BARAMULA" & state=="JAMMU & KASHMIR"
replace block = "B.K PORA" if block=="B.K.PORA" & district=="BADGAM" & state=="JAMMU & KASHMIR"
replace block = "KAKAPORA" if block=="KAKA PORA" & district=="PULWAMA" & state=="JAMMU & KASHMIR"
replace block = "D.H PORA" if block=="D H PORA" & district=="ANANTNAG" & state=="JAMMU & KASHMIR"
replace block = "DURBOK" if block=="DURBUK" & district=="LEH (LADAKH)" & state=="JAMMU & KASHMIR"
replace block = "KHARU" if block=="KHAROO" & district=="LEH (LADAKH)" & state=="JAMMU & KASHMIR"
replace block = "SHARGOLE" if block=="SHARGOL" & district=="KARGIL" & state=="JAMMU & KASHMIR"
replace block = "TAIFSURU" if block=="TAISURU" & district=="KARGIL" & state=="JAMMU & KASHMIR"
replace block = "BHAGWAH" if block=="BHAGWA" & district=="DODA" & state=="JAMMU & KASHMIR"
replace block = "BHARMAUR" if block=="BHARMOUR" & district=="CHAMBA" & state=="HIMACHAL PRADESH"
replace block = "TISA" if block=="TISSA" & district=="CHAMBA" & state=="HIMACHAL PRADESH"
replace block = "LAMBAGAON" if block=="LAMBAGRAON" & district=="KANGRA" & state=="HIMACHAL PRADESH"
replace block = "NAGGAR" if block=="NAGAR" & district=="KULLU" & state=="HIMACHAL PRADESH"
replace block = "DHARAMPUR" if block=="DHARMPUR" & district=="SOLAN" & state=="HIMACHAL PRADESH"
replace block = "DORANGALA" if block=="DORANGLA" & district=="GURDASPUR" & state=="PUNJAB"
replace block = "KALANOUR" if block=="KALANAUR" & district=="GURDASPUR" & state=="PUNJAB"
replace block = "CHOHLA SAHIB" if block=="CHOLA SAHIB" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "HARSA CHHINA" if block=="HARSHA CHHINA" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "DHARAMKOT" if block=="DHARMKOT" & district=="MOGA" & state=="PUNJAB"
replace block = "BHAGTA BHAIKA" if block=="BHAGTA BHAI KA" & district=="BATHINDA" & state=="PUNJAB"
replace block = "NARAYAN BAGAR" if block=="NARAYANBAGAR" & district=="CHAMOLI" & state=="UTTARAKHAND"
replace block = "AUGUSTMUNI" if block=="AUGUST MUNI" & district=="RUDRAPRAYAG" & state=="UTTARAKHAND"
replace block = "THAULDHAR" if block=="THOULDHAR" & district=="TEHRI GARHWAL" & state=="UTTARAKHAND"
replace block = "BIRONKHAL" if block=="BIROKHAL" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "DUGADDA" if block=="DOGADDA" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "JAIHARIKHAL" if block=="JAYHARIKHAL" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "NAINIDANDA" if block=="NAUNIDANDA" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "POKHARA" if block=="POKHRA" & district=="GARHWAL" & state=="UTTARAKHAND"
replace block = "DHAULA DEVI" if block=="DHAULADEVI" & district=="ALMORA" & state=="UTTARAKHAND"
replace block = "BAHADARABAD" if block=="BAHADRABAD" & district=="HARDWAR" & state=="UTTARAKHAND"
replace block = "RAJAUND" if block=="RAJOUND" & district=="KAITHAL" & state=="HARYANA"
replace block = "PILLUKHERA" if block=="PILLU KHERA" & district=="JIND" & state=="HARYANA"
replace block = "BOND KALAN" if block=="BOUND KALAN" & district=="BHIWANI" & state=="HARYANA"
replace block = "NANGAL CHAUDHARY" if block=="NANGAL CHAUDHRY" & district=="MAHENDRAGARH" & state=="HARYANA"
replace block = "JATU SANA" if block=="JATUSANA" & district=="REWARI" & state=="HARYANA"
replace block = "BAWARI" if block=="BAWADI" & district=="JODHPUR" & state=="RAJASTHAN"
replace block = "ARAI" if block=="ARAIN" & district=="AJMER" & state=="RAJASTHAN"
replace block = "BHINDAR" if block=="BHINDER" & district=="UDAIPUR" & state=="RAJASTHAN"
replace block = "TAMEN-RAGA" if block=="TAMEN RAGA" & district=="LOWER SUBANSIRI" & state=="ARUNACHAL PRADESH"
replace block = "RAMLE-BANGO" if block=="RAMLE BANGO" & district=="EAST SIANG" & state=="ARUNACHAL PRADESH"
replace block = "ANELIH-ARZU" if block=="ANELIH-ARJU" & district=="DIBANG VALLEY" & state=="ARUNACHAL PRADESH"
replace block = "KIPHIRE" if block=="KIPHERE" & district=="TUENSANG" & state=="NAGALAND"
replace block = "BHABANIPUR" if block=="BHAWANIPUR" & district=="BARPETA" & state=="ASSAM"
replace block = "RUPOSHI" if block=="RUPSHI" & district=="BARPETA" & state=="ASSAM"
replace block = "BARIGOG BANBHAG" if block=="BARIGOG-BANBHAG" & district=="NALBARI" & state=="ASSAM"
replace block = "PUB NALBARI" if block=="PUB-NALBARI" & district=="NALBARI" & state=="ASSAM"
replace block = "TIHU-BARAMA" if block=="TIHU BARAMA" & district=="NALBARI" & state=="ASSAM"
replace block = "BARBARUAH" if block=="BARBARUA" & district=="DIBRUGARH" & state=="ASSAM"
replace block = "LAHOAL" if block=="LAHOWAL" & district=="DIBRUGARH" & state=="ASSAM"
replace block = "LANGSOMEPI" if block=="LONGSOMEPI" & district=="KARBI ANGLONG" & state=="ASSAM"
replace block = "LUMBAJONG" if block=="LUMBAJANG" & district=="KARBI ANGLONG" & state=="ASSAM"
replace block = "RONGKHANG" if block=="RONGKHAG" & district=="KARBI ANGLONG" & state=="ASSAM"
replace block = "RONGMONGWE" if block=="RONGMONGVE" & district=="KARBI ANGLONG" & state=="ASSAM"
replace block = "TANGI CHOUDWAR" if block=="TANGI-CHOUDWAR" & district=="CUTTACK" & state=="ORISSA"
replace block = "KUKUDA KHANDI" if block=="KUKUDAKHANDI" & district=="GANJAM" & state=="ORISSA"
replace block = "RANGEI LUNDA" if block=="RANGEILUNDA" & district=="GANJAM" & state=="ORISSA"
replace block = "ABHUJHMAD (ORCHHA)" if block=="ABUJHMAD (ORCHA)" & district=="BASTAR" & state=="CHHATTISGARH"
replace block = "ANTHICAD" if block=="ANTHIKKAD" & district=="THRISSUR" & state=="KERALA"
replace block = "CHOWWANNUR" if block=="CHOWANNUR" & district=="THRISSUR" & state=="KERALA"
replace block = "TALIKKULAM" if block=="THALIKULAM" & district=="THRISSUR" & state=="KERALA"
replace block = "VYPIN" if block=="VYPEEN" & district=="ERNAKULAM" & state=="KERALA"
replace block = "SASTHAMKOTTA" if block=="SASTHAMCOTTA" & district=="KOLLAM" & state=="KERALA"
replace block = "THALLY" if block=="THALY" & district=="DHARMAPURI" & state=="TAMIL NADU"
replace block = "ANAKKAVUR" if block=="ANAKAVUR" & district=="TIRUVANNAMALAI" & state=="TAMIL NADU"
replace block = "JAWADHU HILLS" if block=="JAWATHU HILLS" & district=="TIRUVANNAMALAI" & state=="TAMIL NADU"
replace block = "CHINNASALEM" if block=="CHINNA SALEM" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "THIRUKKOYILUR" if block=="THIRUKOILUR" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "TIRUNAVALUR" if block=="THIRUNAVALUR" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "VIKKIRAVANDI" if block=="VIRKRAVANDI" & district=="VILUPPURAM" & state=="TAMIL NADU"
replace block = "AYOTHIYAPATTINAM" if block=="AYODHIAPATTINAM" & district=="SALEM" & state=="TAMIL NADU"
replace block = "PANAMARATHUPATTI" if block=="PANAIMARATHUPATTI" & district=="SALEM" & state=="TAMIL NADU"
replace block = "THALAIVASAL" if block=="TALAVASAL" & district=="SALEM" & state=="TAMIL NADU"
replace block = "VALAPADY" if block=="VALAPPADI" & district=="SALEM" & state=="TAMIL NADU"
replace block = "KABILARMALAI" if block=="KABILAMALAI" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "SENTHAMANGALAM" if block=="SENDAMANGALAM" & district=="NAMAKKAL" & state=="TAMIL NADU"
replace block = "MODAKKURICHI" if block=="MODAKURICHI" & district=="ERODE" & state=="TAMIL NADU"
replace block = "SULTHANPET" if block=="SULTANPET" & district=="COIMBATORE" & state=="TAMIL NADU"
replace block = "THIRUPPUR" if block=="TIRUPUR" & district=="COIMBATORE" & state=="TAMIL NADU"
replace block = "REDDIARCHATTIRAM" if block=="REDDIARCHATRAM" & district=="DINDIGUL" & state=="TAMIL NADU"
replace block = "K.PARAMATHI" if block=="K.PARAMATHY" & district=="KARUR" & state=="TAMIL NADU"
replace block = "PULLAMBADI" if block=="PULLAMPADI" & district=="TIRUCHIRAPPALLI" & state=="TAMIL NADU"
replace block = "ANNAGARAMAM" if block=="ANNAGRAMAM" & district=="CUDDALORE" & state=="TAMIL NADU"
replace block = "THIRUVARANKULAM" if block=="TIRUVARANKULAM" & district=="PUDUKKOTTAI" & state=="TAMIL NADU"
replace block = "THIRUPPUVANAM" if block=="THIRUPUVANAM" & district=="SIVAGANGA" & state=="TAMIL NADU"
replace block = "KALLIKUDI" if block=="KALLLIKUDI" & district=="MADURAI" & state=="TAMIL NADU"
replace block = "KARUNGULAM" if block=="KARUNKULAM" & district=="THOOTHUKKUDI" & state=="TAMIL NADU"
replace block = "KALAKADU" if block=="KALAKAD" & district=="TIRUNELVELI" & state=="TAMIL NADU"
replace block = "VALLIYUR" if block=="VALLIYOOR" & district=="TIRUNELVELI" & state=="TAMIL NADU"
replace block = "MUNCHIRAI" if block=="MUNCHIRA" & district=="KANNIYAKUMARI" & state=="TAMIL NADU"
replace block = "LUDHIANA-I" if block=="LUDHIANA-1" & district=="LUDHIANA" & state=="PUNJAB"
replace block = "LUDHIANA-I" if block=="LUDHIANA 1" & district=="LUDHIANA" & state=="PUNJAB"
replace block = "LUDHIANA-II" if block=="LUDHIANA-2" & district=="LUDHIANA" & state=="PUNJAB"
replace block = "LUDHIANA-II" if block=="LUDHIANA 2" & district=="LUDHIANA" & state=="PUNJAB"
replace block = "GHAGWAL" if block=="GHAGWAL" & district=="JAMMU" & state=="JAMMU & KASHMIR"
replace block = "GANDIWIND" if block=="GANDI WIND" & district=="AMRITSAR" & state=="PUNJAB"
replace block = "BASSI PATHANA" if block=="BASSI PATHANAN" & district=="FATEHGARH SAHIB" & state=="PUNJAB"
replace block = "MEHAL KALAN" if block=="MEHALKALAN" & district=="SANGRUR" & state=="PUNJAB"
replace block = "GHANAUR" if block=="GHANOUR" & district=="PATIALA" & state=="PUNJAB"
replace block = "SANAUR" if block=="SANOUR" & district=="PATIALA" & state=="PUNJAB"
replace block = "HAWAL BAGH" if block=="HAWALBAGH" & district=="ALMORA" & state=="UTTARAKHAND"
replace block = "HASSANPUR" if block=="HASANPUR" & district=="FARIDABAD" & state=="HARYANA"
replace block = "NARSINGPUR" if block=="NARSHINGPUR" & district=="CACHAR" & state=="ASSAM"
replace block = "KUJANG" if block=="KUJANGA" & district=="JAGATSINGHAPUR" & state=="ORISSA"
replace block = "NISCHINTAKOILI" if block=="NISCHINTA KOILI" & district=="CUTTACK" & state=="ORISSA"
replace block = "DASARATHPUR" if block=="DASHARATHPUR" & district=="JAJAPUR" & state=="ORISSA"
replace block = "ATHMALLIK" if block=="ATHAMALIK" & district=="ANUGUL" & state=="ORISSA"
replace block = "K.NUAGAON" if block=="K.NUAGAM" & district=="KANDHAMAL" & state=="ORISSA"
replace block = "HARBHANGA" if block=="HARABHANGA" & district=="BAUDH" & state=="ORISSA"
replace block = "GARIABAND" if block=="GRIYABAND" & district=="RAIPUR" & state=="CHHATTISGARH"
replace block = "SHAHGARH" if block=="SAHGARH" & district=="SULTANPUR" & state=="UTTAR PRADESH"
replace block = "TIHU-BARAMA" if block=="TIHU BARAMA" & district=="NALBARI" & state=="ASSAM"
replace block = "SINGHPORA" if block=="SINGHPORA (KALAN)" & district=="BARAMULA" & state=="JAMMU & KASHMIR"
replace block = "GHAGWAL" if block=="GHAGWAL" & district=="JAMMU" & state=="JAMMU & KASHMIR"
replace block = "DOIWALA" if block=="DOIWALA RISHIKESH" & district=="DEHRADUN" & state=="UTTARAKHAND"
replace block = "NISSING" if block=="NISSING AT CHIRAO" & district=="KARNAL" & state=="HARYANA"
replace block = "KHANDELA" if block=="KHANDELA NAGARPALIKA" & district=="SIKAR" & state=="RAJASTHAN"
replace block = "CHHOTI SARVAN" if block=="CHHOTI SADRI" & district=="BANSWARA" & state=="RAJASTHAN"
replace block = "SARURPUR KHURD" if block=="SARURPUR" & district=="MEERUT" & state=="UTTAR PRADESH"
replace block = "KANGPOKPI" if block=="KANGPOKPI T.D. BLOCK" & district=="SENAPATI (EXCLUDING 3 SUB-DIVISIONS)" & state=="MANIPUR"
replace block = "SAIKUL" if block=="SAIKUL T. D. BLOCK" & district=="SENAPATI (EXCLUDING 3 SUB-DIVISIONS)" & state=="MANIPUR"
replace block = "TAMEI" if block=="TAMEI T.D.BLOCK" & district=="TAMENGLONG" & state=="MANIPUR"
replace block = "TOUSEM" if block=="TOUSEM T.D. BLOCK" & district=="TAMENGLONG" & state=="MANIPUR"
replace block = "CHINGAI" if block=="CHINGAI T.D.BLOCK" & district=="UKHRUL" & state=="MANIPUR"
replace block = "KASOM KHULLEN" if block=="KASOM KHULLEN T.D.BLOCK" & district=="UKHRUL" & state=="MANIPUR"
replace block = "MANIKPUR (PART)" if block=="MANIKPUR" & district=="BONGAIGAON" & state=="ASSAM"
replace block = "GOBARDHANA (PART)" if block=="GOBARDHANA" & district=="BARPETA" & state=="ASSAM"
replace block = "RANI (PART)" if block=="RANI" & district=="KAMRUP" & state=="ASSAM"
replace block = "KAPILI (PART)" if block=="KAPILI PT." & district=="MARIGAON" & state=="ASSAM"
replace block = "KAPILI (PART)" if block=="KAPILI PT." & district=="NAGAON" & state=="ASSAM"
replace block = "DARJEELING PULBAZAR" if block=="DARJEELING MUNICIPALITY" & district=="DARJILING" & state=="WEST BENGAL"
replace block = "KURSEONG" if block=="KURSEONG MUNICIPALITY" & district=="DARJILING" & state=="WEST BENGAL"
replace block = "DHUPGURI" if block=="DHUPGURI MUNICIPALITY" & district=="JALPAIGURI" & state=="WEST BENGAL"
replace block = "ANANDAPUR" if block=="ANANDAPUR N.A.C." & district=="KENDUJHAR" & state=="ORISSA"
replace block = "JODA" if block=="JODA MPL" & district=="KENDUJHAR" & state=="ORISSA"
replace block = "BHUBANESWAR" if block=="BHUBANESWAR MC" & district=="KHORDHA" & state=="ORISSA"
replace block = "PURI SADAR" if block=="PURI MPL" & district=="PURI" & state=="ORISSA"
replace block = "CHIKITI" if block=="CHIKITI N.A.C." & district=="GANJAM" & state=="ORISSA"
replace block = "GANJAM" if block=="GANJAM N.A.C." & district=="GANJAM" & state=="ORISSA"
replace block = "PHANDA (BHOPAL)" if block=="PHANDA GRAMIN" & district=="BHOPAL" & state=="MADHYA PRADESH"
replace block = "KALYAN" if block=="KALYAN DOMBIVLI MNC" & district=="THANE" & state=="MAHARASHTRA"
replace block = "CHALAKUDY (PART)" if block=="CHALAKUDY" & district=="THRISSUR" & state=="KERALA"
replace block = "JALANDHAR (WEST)" if block=="JALANDHAR WEST" & district=="JALANDHAR" & state=="PUNJAB"

	// UP (as much effort as the rest of the states combined!)
replace block = "KAIRANA" if block=="KAIRANA [TOWN AREA]" & district=="MUZAFFARNAGAR" & state=="UTTAR PRADESH"
replace block = "MORADABAD" if block=="MORADABAD CITY BOYS" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "SAMBHAL" if block=="SAMBHAL CITY" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "AMROHA" if block=="AMROHA CITY" & district=="JYOTIBA PHULE NAGAR" & state=="UTTAR PRADESH"
replace block = "HASANPUR" if block=="HASANPUR CITY" & district=="JYOTIBA PHULE NAGAR" & state=="UTTAR PRADESH"
replace block = "MAWANA" if block=="MAWANA NAGAR" & district=="MEERUT" & state=="UTTAR PRADESH"
replace block = "MEERUT" if block=="MEERUT NAGAR" & district=="MEERUT" & state=="UTTAR PRADESH"
replace block = "HAPUR" if block=="HAPUR (MUN.AREA)" & district=="GHAZIABAD" & state=="UTTAR PRADESH"
replace block = "FARIDPUR" if block=="FARIDPUR TOWN" & district=="BAREILLY" & state=="UTTAR PRADESH"
replace block = "KANNAUJ" if block=="KANNAUJ CITY" & district=="KANNAUJ" & state=="UTTAR PRADESH"
replace block = "MAURANIPUR" if block=="MAURANIPUR N.CHETRA" & district=="JHANSI" & state=="UTTAR PRADESH"
replace block = "BIKAPUR" if block=="BIKAPUR TOWN AREA" & district=="FAIZABAD" & state=="UTTAR PRADESH"
replace block = "RUDAULI" if block=="RUDAULI TOWN AREA" & district=="FAIZABAD" & state=="UTTAR PRADESH"
replace block = "TANDA" if block=="TANDA TOWN AREA" & district=="AMBEDKAR NAGAR" & state=="UTTAR PRADESH"
replace block = "PADRAUNA" if block=="PADRAUNA (URBAN)" & district=="KUSHINAGAR" & state=="UTTAR PRADESH"
replace block = "ASAFPUR" if block=="AASAFPUR" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "VERUARWARI" if block=="BERUARBARI" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "JAWAN SIKANDERPUR" if block=="JAWAN" & district=="ALIGARH" & state=="UTTAR PRADESH"
replace block = "FATEHGANJ PASHCHIM" if block=="FATEHGANJ" & district=="BAREILLY" & state=="UTTAR PRADESH"
replace block = "FATEHPUR CHAURASI" if block=="FATEHPUR 84" & district=="UNNAO" & state=="UTTAR PRADESH"
replace block = "KABRAI (MAHOBA)" if block=="KABRAI" & district=="MAHOBA" & state=="UTTAR PRADESH"
replace block = "MAYA BAZAR" if block=="MAYA" & district=="FAIZABAD" & state=="UTTAR PRADESH"
replace block = "PURA BAZAR" if block=="PURA" & district=="FAIZABAD" & state=="UTTAR PRADESH"
replace block = "MUHAMMADABAD GOHNA" if block=="MOHAMMADABAD" & district=="MAU" & state=="UTTAR PRADESH"
replace block = "MUHAMMADABAD GOHNA" if block=="MOHAMMADABAD GOHANA" & district=="MAU" & state=="UTTAR PRADESH"
replace block = "NAGAR (CITY)" if block=="NAGAR" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "NAGAR (CITY)" if block=="NAGAR PALIKA" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "ASMAULI" if block=="ASMOLI" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "CHHAJLET" if block=="CHAJLET" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "MUNDA PANDEY" if block=="MUNDAPANDAY" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "PANWASA" if block=="PAWANSA" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "CHAMRAUA" if block=="CHAMRAUVA" & district=="RAMPUR" & state=="UTTAR PRADESH"
replace block = "SAIDNAGAR" if block=="SAID NAGAR" & district=="RAMPUR" & state=="UTTAR PRADESH"
replace block = "BISRAKH" if block=="VISRAKH" & district=="GAUTAM BUDDHA NAGAR" & state=="UTTAR PRADESH"
replace block = "ARANIYA" if block=="ARNIA" & district=="BULANDSHAHAR" & state=="UTTAR PRADESH"
replace block = "GULAOTHI" if block=="GULAOTI" & district=="BULANDSHAHAR" & state=="UTTAR PRADESH"
replace block = "SYANA" if block=="SYNA" & district=="BULANDSHAHAR" & state=="UTTAR PRADESH"
replace block = "UNCHAGAON" if block=="UCHAGAON" & district=="BULANDSHAHAR" & state=="UTTAR PRADESH"
replace block = "NOHJHIL" if block=="NOHJHEEL" & district=="MATHURA" & state=="UTTAR PRADESH"
replace block = "SHAMSABAD" if block=="SHAMSHABAD" & district=="AGRA" & state=="UTTAR PRADESH"
replace block = "AMANPUR" if block=="AMAPUR" & district=="ETAH" & state=="UTTAR PRADESH"
replace block = "MAREHRA" if block=="MARHARA" & district=="ETAH" & state=="UTTAR PRADESH"
replace block = "SAKIT" if block=="SAKEET" & district=="ETAH" & state=="UTTAR PRADESH"
replace block = "KISHNI" if block=="KISHANI" & district=="MAINPURI" & state=="UTTAR PRADESH"
replace block = "KURAOLI" if block=="KURAWALI" & district=="MAINPURI" & state=="UTTAR PRADESH"
replace block = "AMBIAPUR" if block=="AMBIYAPUR" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "JANAWAI" if block=="JUNAVAI" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "MION" if block=="MIAUN" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "QADAR CHOWK" if block=="QADARCHOWK" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "USAWAN" if block=="USAWA" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "WAZIRGANJ" if block=="WAZEERGANJ" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "AMARIYA" if block=="AMARIA" & district=="PILIBHIT" & state=="UTTAR PRADESH"
replace block = "LALAURIKHERA" if block=="LALORIKHERA" & district=="PILIBHIT" & state=="UTTAR PRADESH"
replace block = "BHAWAL KHERA" if block=="BHAWALKHERA" & district=="SHAHJAHANPUR" & state=="UTTAR PRADESH"
replace block = "DADROL" if block=="DADRAUL" & district=="SHAHJAHANPUR" & state=="UTTAR PRADESH"
replace block = "KATRA (KHUDAGANJ)" if block=="KATRA KHUDAGANJ" & district=="SHAHJAHANPUR" & state=="UTTAR PRADESH"
replace block = "MIRZAPUR" if block=="MIRJAPUR" & district=="SHAHJAHANPUR" & state=="UTTAR PRADESH"
replace block = "BANKEYGANJ" if block=="BANKEGANJ" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "ISANAGAR" if block=="ISA NAGAR" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "KUMBHIGOLA" if block=="KUMBHI-GOLA" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "PHOOLBEHAR" if block=="PHOOL BEHAR" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "RAMIA BEHAR" if block=="RAMIYA BEHAR" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "AILIYA" if block=="ALIYA" & district=="SITAPUR" & state=="UTTAR PRADESH"
replace block = "MACHHREHTA" if block=="MACHHAREHTA" & district=="SITAPUR" & state=="UTTAR PRADESH"
replace block = "RAMPUR MATHURA" if block=="RAMPURMATHURA" & district=="SITAPUR" & state=="UTTAR PRADESH"
replace block = "SAKRAN" if block=="SAKARAN" & district=="SITAPUR" & state=="UTTAR PRADESH"
replace block = "AHRORI" if block=="AHIRORI" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "BAWAN" if block=="BABAN" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "BEHADAR" if block=="BEHANDAR" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "KACHHAUNA" if block=="KACHAUNA" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "KACHHAUNA" if block=="KACHOUNA" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "KOTHWAN" if block=="KOTHAWAN" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "MALLAWAN" if block=="MALLAWA" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "TADIYAWAN" if block=="TANDIYAWA" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "ASOHA" if block=="ASHOHA" & district=="UNNAO" & state=="UTTAR PRADESH"
replace block = "BANGARMAU" if block=="BAGARMAU" & district=="UNNAO" & state=="UTTAR PRADESH"
replace block = "HILAULI" if block=="HILOULI" & district=="UNNAO" & state=="UTTAR PRADESH"
replace block = "MIANGANJ" if block=="MIYAGANJ" & district=="UNNAO" & state=="UTTAR PRADESH"
replace block = "NAWABGANJ" if block=="NAVABGANJ" & district=="UNNAO" & state=="UTTAR PRADESH"
replace block = "GOSAIGANJ" if block=="GOSHAI GANJ" & district=="LUCKNOW" & state=="UTTAR PRADESH"
replace block = "MAL" if block=="MAAL" & district=="LUCKNOW" & state=="UTTAR PRADESH"
replace block = "SAROJANINAGAR" if block=="SAROJNI NAGAR" & district=="LUCKNOW" & state=="UTTAR PRADESH"
replace block = "ROHNIYA" if block=="ROHANIYA" & district=="RAE BARELI" & state=="UTTAR PRADESH"
replace block = "BARHPURA" if block=="BARH PUR" & district=="FARRUKHABAD" & state=="UTTAR PRADESH"
replace block = "MOHAMMADABAD" if block=="MOHAMDABAD" & district=="FARRUKHABAD" & state=="UTTAR PRADESH"
replace block = "RAJEPUR" if block=="RAJE PUR" & district=="FARRUKHABAD" & state=="UTTAR PRADESH"
replace block = "SAURIKH" if block=="SAURIKHA" & district=="KANNAUJ" & state=="UTTAR PRADESH"
replace block = "TALGRAM" if block=="TALAGRAM" & district=="KANNAUJ" & state=="UTTAR PRADESH"
replace block = "AJIT MAL" if block=="AJITMAL" & district=="AURAIYA" & state=="UTTAR PRADESH"
replace block = "ERWA KATRA" if block=="ERVA KATRA" & district=="AURAIYA" & state=="UTTAR PRADESH"
replace block = "SARBANKHERA" if block=="SARVANKHERA" & district=="KANPUR DEHAT" & state=="UTTAR PRADESH"
replace block = "BHITARGAON" if block=="BHITERGAON" & district=="KANPUR NAGAR" & state=="UTTAR PRADESH"
replace block = "NADIGAON" if block=="NADIGAWN" & district=="JALAUN" & state=="UTTAR PRADESH"
replace block = "GURSARAI" if block=="GURSARAIN" & district=="JHANSI" & state=="UTTAR PRADESH"
replace block = "JAKHAURA" if block=="JAKHORA" & district=="LALITPUR" & state=="UTTAR PRADESH"
replace block = "MAHUVA" if block=="MAHUWA" & district=="BANDA" & state=="UTTAR PRADESH"
replace block = "PAHARI" if block=="PAHADI" & district=="CHITRAKOOT" & state=="UTTAR PRADESH"
replace block = "AIRAYA" if block=="AIRAYAN" & district=="FATEHPUR" & state=="UTTAR PRADESH"
replace block = "ASODHAR" if block=="ASHOTHAR" & district=="FATEHPUR" & state=="UTTAR PRADESH"
replace block = "DEVMAI" if block=="DEOMAI" & district=="FATEHPUR" & state=="UTTAR PRADESH"
replace block = "HASWA" if block=="HASAWA" & district=="FATEHPUR" & state=="UTTAR PRADESH"
replace block = "HATHGAON" if block=="HATHGAOM" & district=="FATEHPUR" & state=="UTTAR PRADESH"
replace block = "MALWAN" if block=="MALAWAN" & district=="FATEHPUR" & state=="UTTAR PRADESH"
replace block = "TELYANI" if block=="TELIYANI" & district=="FATEHPUR" & state=="UTTAR PRADESH"
replace block = "VIJAYIPUR" if block=="VIJAIPUR" & district=="FATEHPUR" & state=="UTTAR PRADESH"
replace block = "ASPUR DEOSARA" if block=="AASPUR-DEOSARA" & district=="PRATAPGARH" & state=="UTTAR PRADESH"
replace block = "KALAKANKAR" if block=="KALAKANKER" & district=="PRATAPGARH" & state=="UTTAR PRADESH"
replace block = "MAGRAURA" if block=="MANGRAURA" & district=="PRATAPGARH" & state=="UTTAR PRADESH"
replace block = "RAMPUR SANGRAMGARH" if block=="RAMPUR-SANGRAMGARH" & district=="PRATAPGARH" & state=="UTTAR PRADESH"
replace block = "SANDWA CHANDRIKA" if block=="SADWA-CHANDRIKA" & district=="PRATAPGARH" & state=="UTTAR PRADESH"
replace block = "KARA" if block=="KADA" & district=="KAUSHAMBI" & state=="UTTAR PRADESH"
replace block = "BAHRIA" if block=="BAHARIYA" & district=="ALLAHABAD" & state=="UTTAR PRADESH"
replace block = "JASRA" if block=="JASARA" & district=="ALLAHABAD" & state=="UTTAR PRADESH"
replace block = "PRATAPPUR" if block=="PRATAP PUR" & district=="ALLAHABAD" & state=="UTTAR PRADESH"
replace block = "SHANKARGARH" if block=="SHANKAR GARH" & district=="ALLAHABAD" & state=="UTTAR PRADESH"
replace block = "URUWAN" if block=="URUWA" & district=="ALLAHABAD" & state=="UTTAR PRADESH"
replace block = "DARIYABAD" if block=="DARIYA BAD" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "NINDAURA" if block=="NINDURA" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "PUREDALAI" if block=="PURE DALAI" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "SIDDHAUR" if block=="SIDDHAOR" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "SURATGANJ" if block=="SURAT GANJ" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "TRIVEDIGANJ" if block=="TRIVEDI GANJ" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "MASODHA" if block=="MASAUDHA" & district=="FAIZABAD" & state=="UTTAR PRADESH"
replace block = "MAVAI" if block=="MAWAI" & district=="FAIZABAD" & state=="UTTAR PRADESH"
replace block = "AKHAND NAGAR" if block=="AKHANDNAGAR" & district=="SULTANPUR" & state=="UTTAR PRADESH"
replace block = "DUBEY PUR" if block=="DUBEYPUR" & district=="SULTANPUR" & state=="UTTAR PRADESH"
replace block = "MUSAFIR KHANA" if block=="MUSAFHIR KHANA" & district=="SULTANPUR" & state=="UTTAR PRADESH"
replace block = "BALAHA" if block=="BALHA" & district=="BAHRAICH" & state=="UTTAR PRADESH"
replace block = "CHITAURA" if block=="CHITTAURA" & district=="BAHRAICH" & state=="UTTAR PRADESH"
replace block = "MIHINPURWA" if block=="MIHIN PURVA" & district=="BAHRAICH" & state=="UTTAR PRADESH"
replace block = "NAWABGANJ" if block=="NAWAB GANJ" & district=="BAHRAICH" & state=="UTTAR PRADESH"
replace block = "SHIVPUR" if block=="SHIV PUR" & district=="BAHRAICH" & state=="UTTAR PRADESH"
replace block = "TAJWAPUR" if block=="TAJWA PUR" & district=="BAHRAICH" & state=="UTTAR PRADESH"
replace block = "JAMUNAHA" if block=="JAMUNHA" & district=="SHRAWASTI" & state=="UTTAR PRADESH"
replace block = "VISHESHWARGANJ" if block=="VISHESHWAR GANJ" & district=="SHRAWASTI" & state=="UTTAR PRADESH"
replace block = "HARAYA SATGHARWA" if block=="HARAIYA SATGHARWA" & district=="BALRAMPUR" & state=="UTTAR PRADESH"
replace block = "SHRI DUTT GANJ" if block=="SHRIDUTTGANJ" & district=="BALRAMPUR" & state=="UTTAR PRADESH"
replace block = "CHHAPIA" if block=="CHAPIA" & district=="GONDA" & state=="UTTAR PRADESH"
replace block = "ITIA THOK" if block=="ITIYATHOK" & district=="GONDA" & state=="UTTAR PRADESH"
replace block = "JHANJHARI" if block=="JHANJHRI" & district=="GONDA" & state=="UTTAR PRADESH"
replace block = "MUJHANA" if block=="MUJEHNA" & district=="GONDA" & state=="UTTAR PRADESH"
replace block = "NAWABGANJ" if block=="NAWAB GANJ" & district=="GONDA" & state=="UTTAR PRADESH"
replace block = "PANDRI KRAPAL" if block=="PANDRI KRIPAL" & district=="GONDA" & state=="UTTAR PRADESH"
replace block = "RUPAIDIH" if block=="RUPAIDEEH" & district=="GONDA" & state=="UTTAR PRADESH"
replace block = "BHANWAPUR" if block=="BHANVAPUR" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "KHESRAHA" if block=="KHESARAHA" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "KHUNIYAON" if block=="KHUNIYANV" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "MITHWAL" if block=="MITHAVAL" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "USKA BAZAR" if block=="USAKA BAZAR" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "KUDARAHA" if block=="KUDRAHA" & district=="BASTI" & state=="UTTAR PRADESH"
replace block = "SAU GHAT" if block=="SAUNGHAT" & district=="BASTI" & state=="UTTAR PRADESH"
replace block = "VIKRAM JOT" if block=="VIKRAMJOT" & district=="BASTI" & state=="UTTAR PRADESH"
replace block = "KUDARAHA" if block=="KUDRAHA" & district=="SANT KABIR NAGAR" & state=="UTTAR PRADESH"
replace block = "NATH NAGAR" if block=="NATHNAGAR" & district=="SANT KABIR NAGAR" & state=="UTTAR PRADESH"
replace block = "BRIJMANGANJ" if block=="BRIJMAN GANJ" & district=="MAHRAJGANJ" & state=="UTTAR PRADESH"
replace block = "GHUGHULI" if block=="GHUGHLI" & district=="MAHRAJGANJ" & state=="UTTAR PRADESH"
replace block = "MITHAURA" if block=="MITHOURA" & district=="MAHRAJGANJ" & state=="UTTAR PRADESH"
replace block = "PANIWARA" if block=="PANIYARA" & district=="MAHRAJGANJ" & state=="UTTAR PRADESH"
replace block = "BRAHMPUR" if block=="BRAHMAPUR" & district=="GORAKHPUR" & state=="UTTAR PRADESH"
replace block = "GAUGAHA" if block=="GAGAHA" & district=="GORAKHPUR" & state=="UTTAR PRADESH"
replace block = "JANGAL KODIA" if block=="JANGAL KAUDIA" & district=="GORAKHPUR" & state=="UTTAR PRADESH"
replace block = "KAURI RAM" if block=="KAUDIRAM" & district=="GORAKHPUR" & state=="UTTAR PRADESH"
replace block = "PALI" if block=="PAALI" & district=="GORAKHPUR" & state=="UTTAR PRADESH"
replace block = "DUDHAHI" if block=="DUDAHI" & district=="KUSHINAGAR" & state=="UTTAR PRADESH"
replace block = "DUDHAHI" if block=="DUDHI" & district=="KUSHINAGAR" & state=="UTTAR PRADESH"
replace block = "FAZILNAGAR" if block=="FAZIL NAGAR" & district=="KUSHINAGAR" & state=="UTTAR PRADESH"
replace block = "BANKATA" if block=="BANAKATA" & district=="DEORIA" & state=="UTTAR PRADESH"
replace block = "BHALUANI" if block=="BHLUANI" & district=="DEORIA" & state=="UTTAR PRADESH"
replace block = "DESAI DEORIA" if block=="DESAHI DEORIA" & district=="DEORIA" & state=="UTTAR PRADESH"
replace block = "ATRAULIA" if block=="ATRAULIYA" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "HARAIYA" if block=="HARRAIYA" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "MAHRAJGANJ" if block=="MAHARAJ GANJ" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "MARTINGANJ" if block=="MARTIN GANJ" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "PALHANI" if block=="PALAHNI" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "PAWAI" if block=="PAWAE" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "SATHIYAON" if block=="SATHIYAN" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "TAHBARPUR" if block=="TAHBERPUR" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "DOHARI GHAT" if block=="DOHRIGHAT" & district=="MAU" & state=="UTTAR PRADESH"
replace block = "KOPAGANJ" if block=="KOPAGANG" & district=="MAU" & state=="UTTAR PRADESH"
replace block = "BELHARI" if block=="BELAHARI" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "DUBHAD" if block=="DUBAHAR" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "MANIYAR" if block=="MANIAR" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "NAGRA" if block=="NAGARA" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "SIAR" if block=="SEAR" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "SOHAON" if block=="SOHAWN" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "BAKSHA" if block=="BUKSHA" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "DHARAMPUR" if block=="DHARMAPUR" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "MUFTIGANJ" if block=="MUFTI GUNJ" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "SUITHAKALA" if block=="SUITHA KALA" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "SUJANGANJ" if block=="SUJAN GUNJ" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "BHANWARKOL" if block=="BHAWARCOL" & district=="GHAZIPUR" & state=="UTTAR PRADESH"
replace block = "REVATIPUR" if block=="REOTIPUR" & district=="GHAZIPUR" & state=="UTTAR PRADESH"
replace block = "BARHANI" if block=="BARAHANI" & district=="CHANDAULI" & state=="UTTAR PRADESH"
replace block = "CHAHNIYA" if block=="CHAHANIYA" & district=="CHANDAULI" & state=="UTTAR PRADESH"
replace block = "DIGH" if block=="DEEGH" & district=="SANT RAVIDAS NAGAR BHADOHI" & state=="UTTAR PRADESH"
replace block = "SURIYAWAN" if block=="SURIYAVAN" & district=="SANT RAVIDAS NAGAR BHADOHI" & state=="UTTAR PRADESH"
replace block = "CHHANVEY" if block=="CHHANBAY" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "HALLIA" if block=="HALIA" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "JAMALPUR" if block=="JAMAL PUR" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "KON" if block=="KONE" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "NARAINPUR" if block=="NARAYANPUR" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "SIKHAR" if block=="SEEKHAR" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "HAISAR BAZAR" if block=="HAINSAR BAZAR" & district=="SANT KABIR NAGAR" & state=="UTTAR PRADESH"
replace block = "BADRAON" if block=="BADRAW" & district=="MAU" & state=="UTTAR PRADESH"
replace block = "FATEHPUR MADAUN" if block=="FATEHPUR MANDAON" & district=="MAU" & state=="UTTAR PRADESH"
replace block = "CHHANVEY" if block=="CHHANBEY" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "BAGHPAT" if block=="BAGPAT" & district=="BAGHPAT" & state=="UTTAR PRADESH"
replace block = "NAUTANWA" if block=="NOUTANWA" & district=="MAHRAJGANJ" & state=="UTTAR PRADESH"
replace block = "BALLIA" if block=="BALLIA N.P." & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "BAREILLY" if block=="BAREILLY TOWN" & district=="BAREILLY" & state=="UTTAR PRADESH"
replace block = "BASTI" if block=="BASTI SADAR" & district=="BASTI" & state=="UTTAR PRADESH"
replace block = "BILSI" if block=="BILSI CITY" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "BUDAUN" if block=="BUDAUN CITY" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "DEORIA" if block=="DEORIA NAGAR CHHETR" & district=="DEORIA" & state=="UTTAR PRADESH"
replace block = "ETAH" if block=="ETAH (URBAN)" & district=="ETAH" & state=="UTTAR PRADESH"
replace block = "ETAWAH" if block=="ETAWAH NAGAR CHETRA" & district=="ETAWAH" & state=="UTTAR PRADESH"
replace block = "FAIZABAD" if block=="FAIZABAD TOWN AREA" & district=="FAIZABAD" & state=="UTTAR PRADESH"
replace block = "GHAZIABAD" if block=="GHAZIABAD (MUN.AREA)" & district=="GHAZIABAD" & state=="UTTAR PRADESH"
replace block = "GHAZIPUR" if block=="GHAZIPUR SADAR" & district=="GHAZIPUR" & state=="UTTAR PRADESH"
replace block = "JAUNPUR" if block=="JAUNPUR [NAGAR]" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "JHANSI" if block=="JHANSI NAGARCHETRA" & district=="JHANSI" & state=="UTTAR PRADESH"
replace block = "GOLA GOKARAN NATH" if block=="GOLA" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "TAMKUHI RAJ" if block=="TAMKUHI" & district=="KUSHINAGAR" & state=="UTTAR PRADESH"
replace block = "CHANDAUSI" if block=="CHANDAUSI CITY" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "SULTANPUR" if block=="SULTANPUR CITY" & district=="SULTANPUR" & state=="UTTAR PRADESH"
replace block = "MORADABAD" if block=="MORADABAD CITY GIRLS" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "PHULPUR" if block=="PHOOLPUR" & district=="ALLAHABAD" & state=="UTTAR PRADESH"
replace block = "SORAON" if block=="SORAM" & district=="ALLAHABAD" & state=="UTTAR PRADESH"
replace block = "AZAMGARH" if block=="AZAMGRAH" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "MEHNAGAR" if block=="MEHNAGER" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "BARAUT" if block=="BAROUT" & district=="BAGHPAT" & state=="UTTAR PRADESH"
replace block = "KHEKADA" if block=="KHEKRA" & district=="BAGHPAT" & state=="UTTAR PRADESH"
replace block = "KAISERGANJ" if block=="KAISER GANJ" & district=="BAHRAICH" & state=="UTTAR PRADESH"
replace block = "MAHASI" if block=="MAHSI" & district=="BAHRAICH" & state=="UTTAR PRADESH"
replace block = "BANSDIH" if block=="BANSDEEH" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "RASRA" if block=="RASARA" & district=="BALLIA" & state=="UTTAR PRADESH"
replace block = "BANDA" if block=="BISANDA" & district=="BANDA" & state=="UTTAR PRADESH"
replace block = "FATEHPUR" if block=="FATEH PUR" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "HAIDERGARH" if block=="HAIDAR GARH" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "RAMNAGAR" if block=="RAM NAGAR" & district=="BARABANKI" & state=="UTTAR PRADESH"
replace block = "MEERGANJ" if block=="MIRGANJ" & district=="BAREILLY" & state=="UTTAR PRADESH"
replace block = "HARRAIYA" if block=="HARRIYA" & district=="BASTI" & state=="UTTAR PRADESH"
replace block = "GUNNAUR" if block=="GUNNOR" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "CHAKIA" if block=="CHAKIYA" & district=="CHANDAULI" & state=="UTTAR PRADESH"
replace block = "SALEMPUR" if block=="SALIMPUR" & district=="DEORIA" & state=="UTTAR PRADESH"
replace block = "JASWANTNAGAR" if block=="JASWANT NAGAR" & district=="ETAWAH" & state=="UTTAR PRADESH"
replace block = "SAIFAI" if block=="SAIFAIE" & district=="ETAWAH" & state=="UTTAR PRADESH"
replace block = "KAIMGANJ" if block=="KAIM GANJ" & district=="FARRUKHABAD" & state=="UTTAR PRADESH"
replace block = "GARHMUKTESHWAR" if block=="GARH MUKTESWAR" & district=="GHAZIABAD" & state=="UTTAR PRADESH"
replace block = "MOHAMMADABAD" if block=="MOHAMDABAD" & district=="GHAZIPUR" & state=="UTTAR PRADESH"
replace block = "CAMPIERGANJ" if block=="CAMPIARGANJ" & district=="GORAKHPUR" & state=="UTTAR PRADESH"
replace block = "MAUDAHA" if block=="MAUDHA" & district=="HAMIRPUR" & state=="UTTAR PRADESH"
replace block = "BADLAPUR" if block=="BADLA PUR" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "SHAHGANJ" if block=="SHAH GUNJ" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "DHANAURA" if block=="DHANORA" & district=="JYOTIBA PHULE NAGAR" & state=="UTTAR PRADESH"
replace block = "CHHIBRAMAU" if block=="CHIBRAMAU" & district=="KANNAUJ" & state=="UTTAR PRADESH"
replace block = "CHAIL" if block=="CHAYAL" & district=="KAUSHAMBI" & state=="UTTAR PRADESH"
replace block = "SIRATHU" if block=="SIRATU" & district=="KAUSHAMBI" & state=="UTTAR PRADESH"
replace block = "MOHAMMDI" if block=="MOHAMMADI" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "KASYA" if block=="KASIA" & district=="KUSHINAGAR" & state=="UTTAR PRADESH"
replace block = "PADRAUNA" if block=="PADARAUNA" & district=="KUSHINAGAR" & state=="UTTAR PRADESH"
replace block = "MOHANLALGANJ" if block=="MOHAN LAL GANJ" & district=="LUCKNOW" & state=="UTTAR PRADESH"
replace block = "MAHARAJGANJ" if block=="MAHRAJGANJ" & district=="MAHRAJGANJ" & state=="UTTAR PRADESH"
replace block = "NICHLAUL" if block=="NICHLOUL" & district=="MAHRAJGANJ" & state=="UTTAR PRADESH"
replace block = "MAT" if block=="MANT" & district=="MATHURA" & state=="UTTAR PRADESH"
replace block = "MAHARAJGANJ" if block=="MAHRAJGANJ" & district=="RAE BARELI" & state=="UTTAR PRADESH"
replace block = "SHAHABAD" if block=="SHAHBAD" & district=="RAMPUR" & state=="UTTAR PRADESH"
replace block = "MEHDAWAL" if block=="MEHNDAVAL" & district=="SANT KABIR NAGAR" & state=="UTTAR PRADESH"
replace block = "POWAYAN" if block=="PUWAYA" & district=="SHAHJAHANPUR" & state=="UTTAR PRADESH"
replace block = "DOMARIYAGANJ" if block=="DUMARIYAGANJ" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "ITWA" if block=="ITAVA" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "SHOHRATGARH" if block=="SOHARATGARH" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "SHOHRATGARH" if block=="SHOHARATGARH" & district=="SIDDHARTHNAGAR" & state=="UTTAR PRADESH"
replace block = "MAHMUDABAD" if block=="MAHMOODABAD" & district=="SITAPUR" & state=="UTTAR PRADESH"
replace block = "THAKURDWARA" if block=="THAKUR DUWARA" & district=="MORADABAD" & state=="UTTAR PRADESH"
replace block = "SAHAWAR" if block=="SAHAVAR" & district=="ETAH" & state=="UTTAR PRADESH"
replace block = "PALIA" if block=="PAL" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "PALIA" if block=="PALIYA" & district=="KHERI" & state=="UTTAR PRADESH"
replace block = "SANDILA" if block=="SANDI" & district=="HARDOI" & state=="UTTAR PRADESH"
replace block = "BHITI" if block=="BHEETI" & district=="AMBEDKAR NAGAR" & state=="UTTAR PRADESH"
replace block = "RUDHAULI" if block=="RUDHOLI" & district=="BASTI" & state=="UTTAR PRADESH"
replace block = "AZAMGARH" if block=="AZMATGARH" & district=="AZAMGARH" & state=="UTTAR PRADESH"
replace block = "SHAHGANJ" if block=="SHAH GANJ" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "ZAMANIA" if block=="ZAKHANIA" & district=="GHAZIPUR" & state=="UTTAR PRADESH"
replace block = "LALGANJ" if block=="LAL GANG" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "MARIHAN" if block=="MERIHAN" & district=="MIRZAPUR" & state=="UTTAR PRADESH"
replace block = "ARAJILINE" if block=="ARAJILINES" & district=="VARANASI" & state=="UTTAR PRADESH"
replace block = "DEORIA" if block=="DEORIA SADAR" & district=="DEORIA" & state=="UTTAR PRADESH"
replace block = "MANDAWARA" if block=="MADAWRA" & district=="LALITPUR" & state=="UTTAR PRADESH"

	// based on VD 2011 BLOCK2 names!
replace block = "BALLIA KHERI" if block=="BALIA KHEDI" & district=="SAHARANPUR" & state=="UTTAR PRADESH"
replace block = "PUWARKA" if block=="PUVARKA" & district=="SAHARANPUR" & state=="UTTAR PRADESH"
replace block = "SARSAWAN" if block=="SARSAVA" & district=="SAHARANPUR" & state=="UTTAR PRADESH"
replace block = "BAGHARA" if block=="BAGHRA" & district=="MUZAFFARNAGAR" & state=="UTTAR PRADESH"
replace block = "PURKAZI" if block=="PURKAJI" & district=="MUZAFFARNAGAR" & state=="UTTAR PRADESH"
replace block = "THANA BHAWAN" if block=="THANABHAWAN" & district=="MUZAFFARNAGAR" & state=="UTTAR PRADESH"
replace block = "AFZALGARH" if block=="AFZALGRAH" & district=="BIJNOR" & state=="UTTAR PRADESH"
replace block = "PARIKSHITGARH" if block=="PARIKSHIT GARH" & district=="MEERUT" & state=="UTTAR PRADESH"
replace block = "CHHAPRAULI" if block=="CHHAPROLI" & district=="BAGHPAT" & state=="UTTAR PRADESH"
replace block = "MURADNAGAR" if block=="MURAD NAGAR" & district=="GHAZIABAD" & state=="UTTAR PRADESH"
replace block = "CHAUMUHA" if block=="CHAUMUHAN" & district=="MATHURA" & state=="UTTAR PRADESH"
replace block = "GOVARDHAN" if block=="GOVERDHAN" & district=="MATHURA" & state=="UTTAR PRADESH"
replace block = "ACHHNERA" if block=="ACCHNERA" & district=="AGRA" & state=="UTTAR PRADESH"
replace block = "KHANDAULI" if block=="KHANDOLI" & district=="AGRA" & state=="UTTAR PRADESH"
replace block = "SARSOL" if block=="SARSAUL" & district=="KANPUR NAGAR" & state=="UTTAR PRADESH"
replace block = "BABA BELKHARNATH" if block=="BABA BHELKHARNATH" & district=="PRATAPGARH" & state=="UTTAR PRADESH"
replace block = "TARKULWA" if block=="TARAKULAWA" & district=="DEORIA" & state=="UTTAR PRADESH"
replace block = "CHIRAI GAON" if block=="CHIRAIGAON" & district=="VARANASI" & state=="UTTAR PRADESH"
replace block = "KASHI VIDYA PEETH" if block=="KASHIVIDYAPEETH" & district=="VARANASI" & state=="UTTAR PRADESH"
replace block = "SEVAPURI" if block=="SEWAPURI" & district=="VARANASI" & state=="UTTAR PRADESH"
replace block = "PUWARKA" if block=="PUNWARKA" & district=="SAHARANPUR" & state=="UTTAR PRADESH"
replace block = "JANAWAI" if block=="JUNAWAI" & district=="BUDAUN" & state=="UTTAR PRADESH"
replace block = "RAMNAGAR" if block=="RAM NAGAR" & district=="CHITRAKOOT" & state=="UTTAR PRADESH"
replace block = "SHAHGARH" if block=="SAHGARH" & district=="SULTANPUR" & state=="UTTAR PRADESH"
replace block = "KARANJAKALA" if block=="KARANJA KALA" & district=="JAUNPUR" & state=="UTTAR PRADESH"
replace block = "MYORPUR" if block=="MYOURPUR" & district=="SONBHADRA" & state=="UTTAR PRADESH"


}

	// standardize district names (districts split across blocks)
{
replace district = "WEST SIANG" if state=="ARUNACHAL PRADESH" & district=="SIANG" & dt_code==20 & inlist(block,"RUMGONG","KAYING-PAYUM")==1
replace dt_code = 7 if state=="ARUNACHAL PRADESH" & district=="WEST SIANG" & dt_code==20 & inlist(block,"RUMGONG","KAYING-PAYUM")==1
replace district = "EAST SIANG" if state=="ARUNACHAL PRADESH" & district=="SIANG" & dt_code==20 & inlist(block,"RUMGONG","KAYING-PAYUM")==0
replace dt_code = 8 if state=="ARUNACHAL PRADESH" & district=="EAST SIANG" & dt_code==20 & inlist(block,"RUMGONG","KAYING-PAYUM")==0
replace district = "AHMADABAD" if state=="GUJARAT" & district=="BOTAD" & dt_code==28 & inlist(block,"RANPUR")==1
replace dt_code = 7 if state=="GUJARAT" & district=="AHMADABAD" & dt_code==28 & inlist(block,"RANPUR")==1
replace district = "BHAVNAGAR" if state=="GUJARAT" & district=="BOTAD" & dt_code==28 & inlist(block,"RANPUR")==0
replace dt_code = 14 if state=="GUJARAT" & district=="BHAVNAGAR" & dt_code==28 & inlist(block,"RANPUR")==0
replace district = "KHEDA" if state=="GUJARAT" & district=="MAHISAGAR" & dt_code==31 & inlist(block,"BALASINOR","VIRPUR")==1
replace dt_code = 16 if state=="GUJARAT" & district=="KHEDA" & dt_code==31 & inlist(block,"BALASINOR","VIRPUR")==1
replace district = "PANCH MAHALS" if state=="GUJARAT" & district=="MAHISAGAR" & dt_code==31 & inlist(block,"BALASINOR","VIRPUR")==0
replace dt_code = 17 if state=="GUJARAT" & district=="PANCH MAHALS" & dt_code==31 & inlist(block,"BALASINOR","VIRPUR")==0
replace district = "RAJKOT" if state=="GUJARAT" & district=="MORBI" & dt_code==33 & inlist(block,"HALVAD")==0
replace dt_code = 9 if state=="GUJARAT" & district=="RAJKOT" & dt_code==33 & inlist(block,"HALVAD")==0
replace district = "SURENDRANAGAR" if state=="GUJARAT" & district=="MORBI" & dt_code==33 & inlist(block,"HALVAD")==1
replace dt_code = 8 if state=="GUJARAT" & district=="SURENDRANAGAR" & dt_code==33 & inlist(block,"HALVAD")==1
replace district = "BARPETA" if state=="ASSAM" & district=="BAKSA" & dt_code==24 & inlist(block,"JALAH")==1
replace dt_code = 5 if state=="ASSAM" & district=="BARPETA" & dt_code==24 & inlist(block,"JALAH")==1
replace district = "NALBARI" if state=="ASSAM" & district=="BAKSA" & dt_code==24 & inlist(block,"JALAH")==0
replace dt_code = 7 if state=="ASSAM" & district=="NALBARI" & dt_code==24 & inlist(block,"JALAH")==0
replace block = "TIHU-BARAMA" if block=="TIHU BARAMA" & district=="NALBARI" & state=="ASSAM"

	// CHECK MATCH RATES
replace district = "GONDA" if state=="UTTAR PRADESH" & district=="ALIGARH" & dt_code==12 & inlist(block,"GONDA")==1
replace dt_code = 53 if state=="UTTAR PRADESH" & district=="GONDA" & dt_code==12 & inlist(block,"GONDA")==1
replace district = "BANDA" if state=="UTTAR PRADESH" & district=="SHAHJAHANPUR" & dt_code==22 & inlist(block,"BANDA")==1
replace dt_code = 40 if state=="UTTAR PRADESH" & district=="BANDA" & dt_code==22 & inlist(block,"BANDA")==1
replace district = "MIRZAPUR" if state=="UTTAR PRADESH" & district=="SHAHJAHANPUR" & dt_code==22 & inlist(block,"MIRZAPUR")==1
replace dt_code = 69 if state=="UTTAR PRADESH" & district=="MIRZAPUR" & dt_code==22 & inlist(block,"MIRZAPUR")==1
replace district = "MIRZAPUR" if state=="BIHAR" & district=="SHAHJAHANPUR" & dt_code==22 & inlist(block,"MIRZAPUR")==1

	// CHECK FOR ADDITIONAL UNMATCHED BLOCKS
replace district = "RAE BARELI" if state=="UTTAR PRADESH" & district=="AMETHI - CSM NAGAR" & dt_code==73 & inlist(block,"SALON","TILOI")==1
replace dt_code = 28 if state=="UTTAR PRADESH" & district=="RAE BARELI" & dt_code==73 & inlist(block,"SALON","TILOI")==1
replace district = "SULTANPUR" if state=="UTTAR PRADESH" & district=="AMETHI - CSM NAGAR" & dt_code==73 & inlist(block,"SALON","TILOI")==0
replace dt_code = 49 if state=="UTTAR PRADESH" & district=="SULTANPUR" & dt_code==73 & inlist(block,"SALON","TILOI")==0
replace district = "RAE BARELI" if state=="UTTAR PRADESH" & district=="CSMAHARAJ NAGAR" & dt_code==73 & inlist(block,"SALON","TILOI")==1
replace dt_code = 28 if state=="UTTAR PRADESH" & district=="RAE BARELI" & dt_code==73 & inlist(block,"SALON","TILOI")==1
replace district = "SULTANPUR" if state=="UTTAR PRADESH" & district=="CSMAHARAJ NAGAR" & dt_code==73 & inlist(block,"SALON","TILOI")==0
replace dt_code = 49 if state=="UTTAR PRADESH" & district=="SULTANPUR" & dt_code==73 & inlist(block,"SALON","TILOI")==0

**** DISE assigns UP block NAWABGANJ to 5 districts: BAHRAICH, BAREILLY, FARRUKHABAD, GONDA, UNNAO 
**** CENS assigns UP block NAWABGANJ to 2 districts: BAREILLY, BARABANKI

**** DISE assigns UP block RAMNAGAR to 5 districts: AMBEDKAR NAGAR, BARABANKI, BAREILLY, BASTI, CHITRAKOOT
**** CENS assigns UP block RAMNAGAR to 1 district: BARABANKI

**** DISE assigns UP block JALALPUR to 2 districts: AMBEDKAR NAGAR, JAUNPUR
**** CENS assigns UP block JALALPUR to 1 district: AMBEDKAR NAGAR

**** DISE assigns UP block JALALABAD to 2 districts: SHAHJAHANPUR, KANNAUJ
**** CENS assigns UP block JALALABAD to 1 district: SHAHJAHANPUR

**** DISE assigns UP block NAUGARH to 2 districts: SIDDHARTHNAGAR, CHANDAULI
**** CENS assigns UP block NAUGARH to 1 district: SIDDHARTHNAGAR

**** DISE assigns UP block RUDAULI to 2 districts: BARABANKI, FAIZABAD
**** CENS assigns UP block RUDAULI to 1 district: FAIZABAD

**** DISE assigns UP block FATEHPUR to 1 district: FATEHPUR
**** CENS assigns UP block FATEHPUR to 2 districts: BARABANKI, FATEHPUR

**** DISE assigns UP block PAYAGPUR to 2 districts: BAHRAICH, SHRAWASTI
**** CENS assigns UP block PAYAGPUR to 1 district: SHRAWASTI

**** DISE assigns UP block MOHAMMADABAD to 2 districts: FARRUKHABAD, GHAZIPUR
**** CENS assigns UP block MOHAMMADABAD to 1 district: GHAZIPUR

**** DISE assigns UP block PHULPUR to 1 district: ALLAHABAD
**** CENS assigns UP block PHULPUR to 2 districts: ALLAHABAD, AZAMGARH

*** UP district FATEHPUR is a disaster!

**** DISE assigns BIHAR block MADHUBANI to 1 district: MADHUBANI
**** CENS assigns BIHAR block MADHUBANI to 2 districts: PASHCHIM CHAMPARAN, MADHUBANI

**** DISE assigns BIHAR block CHANAN to 2 districts: LAKHISARAI, BANKA
**** CENS assigns BIHAR block CHANAN to 1 district: BANKA

**** DISE assigns BIHAR block KISHANGANJ to 1 district: KISHANGANJ
**** CENS assigns BIHAR block KISHANGANJ to 2 districts: KISHANGANJ, MADHEPURA

**** DISE assigns PUNJAB block DERA BASSI to 2 districtS: PATIALA, RUPNAGAR
**** CENS assigns PUNJAB block DERA BASSI to 1 district: PATIALA

**** 3 ASSAM DISTRICTS: CHIRANG, KAMRUP-METRO. KARBI ANGLONG

**** DISE assigns HARYANA block NUH to 2 districtS: FARIDABAD, GURGAON
**** CENS assigns HARYANA block NUH to 1 district: GURGAON
}
  // additional block spellings to fix?
{
/*
blockS
DERABASSI
DERA BASSI

blockS
SULT
SALT

blockS
BASSI
BASSI PATHANAN

blockS
CHOTISARVAN (PEEPALKHUNT)
PEEPALKHOONT

blockS
PUVARKA
PUNWARKA

blockS
NIDHAULI KALAN
NIDHAULI KALA

blockS
SUMRAIR
SUMRER
SAMRER

blockS
JANAWAI
JUNAWAI

blockS
JHINJHAK
JHIJHAK

blockS
PP KAMAICHA
PRATAPPUR KAMAICHA

blockS
SUKUL BAZAR
SHUKUL BAZAR

blockS
GHOSI
MOHAMMADABAD GOHANA

blockS
MACHHALI SHAHAR
MACHLI SHAHAR

blockS
SUJANGANJ
SUJAN GANJ

blockS
BURSATHI
BARSATHI

blockS
NERAYEN PUR
NARAINPUR

blockS
MYORPUR
MYOURPUR

blockS
MOHARA
MUHRA

blockS
KIMIN
DOIMUKH-KIMIN

blockS
CHAMBANG/YANGTE
CHAMBANG-GANGTE

blockS
PIPSORANG
TALI/PIPSORANG

blockS
LIMEKING
NACHO

blockS
UMREN
UMERAIN

blockS
SAWOMBUNG IMPHAL EAST I
SAWOMBUNG

blockS
MAJHIAON
MANJHIAON

blockS
BAGHMARA
BAGMARA

blockS
CANDANKIYARI
CANDANKIYARI 2

blockS
DASARATHPUR
DASHARATHPUR

blockS
K.NUAGAON
K.NUAGAM

blockS
M.BARODIYA
M. BARODIYA

blockS
PHANDA GRAMIN
PHANDA

blockS
CHANDUR BAZAR
CHANDUR BZ

blockS
SOUTH1
SOUTH

blockS
THIRUKALLUKUNDRAM
THIRUKALUKUNDRAM

blockS
THIRUPPATHUR
THIRUPPATUR
*/
}




egen temp_min = min(dt_code), by(st_code state district)
egen temp_max = max(dt_code), by(st_code state district)
replace dt_code = temp_min if temp_min<temp_max
drop temp*

****** UNCOMMENT TO DEBUG DISTRICT/BLOCK MATCHES
/*
duplicates drop
rename block blockS
joinby state st_code district dt_code using "$smerge/names_for_merge_temp_blocks.dta", ///
       unmatched(both) _merge(merge_dt)
drop bk_code* block block11 district11 pca01_id
duplicates drop
rename district districtS 
rename dt_code dt_codeS
rename blockS block
joinby state st_code block using "$smerge/names_for_merge_temp_blocks.dta", ///
       unmatched(both) _merge(merge_bk)
sort state districtS block
*egen min_merge_dt = min(merge_dt), by(st_code districtS)
*egen max_merge_bk = max(merge_bk), by(st_code districtS)
*keep if min_merge_dt==1 & max_merge_bk==3
br state st_code dt_code dt_codeS district districtS block merge_dt merge_bk if merge_bk==3 & merge_dt==1
keep if merge_bk==3
collapse (count) block=merge_bk, by(state st_code district dt_code districtS dt_codeS)
*/
****** 


replace village = upper(trim(itrim(village)))
drop if village==""
gen schv9_id = substr(school_code,1,9)
sort st_code dt_code district
order state district block village school_code
egen schv_id = group(st_code state district block village dt_code)
save "$schools/schools_ALL_for_merge_all.dta", replace

use "$schools/schools_ALL_for_merge_all.dta", clear
collapse (mean) nschools (count) count_sch_id=sch_id, by(st_code state dt_code district block village schv_id)
unique schv_id
compress
save "$schools/schools_ALL_for_merge.dta", replace
}


********************************************************************************
********************************************************************************

** Step 3: Make sure (almost) all states & districts & blocks have exact matches, copy bk_codes
{
	// For unmatched block names, tweak spellings to match PCA 2001 block names
{
use "$schools/schools_ALL_for_merge.dta", clear
keep state st_code district dt_code block
duplicates drop
merge 1:m state st_code district dt_code block using "$smerge/names_for_merge.dta", gen(merge_bk)
keep state st_code district dt_code block bk_code_pca merge*
duplicates drop 
sort state district block

  // Code to iterate to macth PCA 2001 block names (commented out after iterating)
/*
keep if merge_bk<3 
gen block_name_merge = ""  // create field for merge name, to go back and replace when opening schools dataset
gen q = `"""'
*/
/*
*Iterate 2x to correct blocks that are 1-2 letters off
gen block_pca_above = block[_n-1] if merge_bk[_n-1]==2
gen block_pca_below = block[_n+1] if merge_bk[_n+1]==2
strdist block block_pca_above if merge_bk==1, gen(dist_above)
strdist block block_pca_below if merge_bk==1, gen(dist_below)
br block block_pca_above dist_above if dist_above<3
br block block_pca_below dist_below if dist_below<3
replace block_name_merge = block_pca_above if merge_bk==1 & merge_bk[_n-1]==2 & dist_above<3 & dist_below>3 & state==state[_n-1] & district==district[_n-1]  
replace block_name_merge = block_pca_below if merge_bk==1 & merge_bk[_n+1]==2 & dist_below<3 & dist_above>3 & state==state[_n+1] & district==district[_n+1]  
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block,-1)!="I" & word(block,-1)!="II" & word(block,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/
/*
*Iterate 1x to correct blocks that have a matching word
gen block_pca_above = block[_n-1] if merge_bk[_n-1]==2
gen block_pca_below = block[_n+1] if merge_bk[_n+1]==2
gen block_name_merge_above = block_pca_above if merge_bk==1 & merge_bk[_n-1]==2 & word(block,1)==word(block_pca_above,1) & state==state[_n-1] & district==district[_n-1]
gen block_name_merge_below = block_pca_below if merge_bk==1 & merge_bk[_n+1]==2 & word(block,1)==word(block_pca_below,1) & state==state[_n+1] & district==district[_n+1]
br state district block block_pca* block_name_merge_* if block_name_merge_above!="" | block_name_merge_below!=""
replace block_name_merge = block_name_merge_above if block_name_merge=="" & word(block_name_merge_above,-1)!="I" & word(block_name_merge_above,-1)!="II" & word(block_name_merge_above,-1)!="III" & word(block_name_merge_above,-1)!="WEST" & word(block_name_merge_above,-1)!="EAST" & word(block_name_merge_above,-1)!="SOUTH" & word(block_name_merge_above,-1)!="NORTH" & word(block,-1)!="I" & word(block,-1)!="II" & word(block,-1)!="III" & word(block,-1)!="WEST" & word(block,-1)!="EAST" & word(block,-1)!="SOUTH" & word(block,-1)!="NORTH"  
replace block_name_merge = block_name_merge_below if block_name_merge=="" & word(block_name_merge_below,-1)!="I" & word(block_name_merge_below,-1)!="II" & word(block_name_merge_below,-1)!="III" & word(block_name_merge_below,-1)!="WEST" & word(block_name_merge_below,-1)!="EAST" & word(block_name_merge_below,-1)!="SOUTH" & word(block_name_merge_below,-1)!="NORTH" & word(block,-1)!="I" & word(block,-1)!="II" & word(block,-1)!="III" & word(block,-1)!="WEST" & word(block,-1)!="EAST" & word(block,-1)!="SOUTH" & word(block,-1)!="NORTH"  
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block,-1)!="I" & word(block,-1)!="II" & word(block,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/

drop if merge_bk==2
replace bk_code = . if block=="SIRPUR" & district=="ADILABAD" & state=="ANDHRA PRADESH"
duplicates drop
merge 1:m state st_code district dt_code block using "$schools/schools_ALL_for_merge.dta", nogen
order st_code state dt_code district block bk_code_pca
sort  st_code state dt_code district block bk_code_pca
save "$schools/schools_ALL_for_merge.dta", replace
}
  ***

	// For remaining unmatched, try PCA 2011 block names
{
use "$schools/schools_ALL_for_merge.dta", clear
keep st_code state dt_code district block merge*
rename block block11
duplicates drop
merge 1:m st_code state dt_code district block11 using "$smerge/names_for_merge.dta", gen(merge_bk11)
keep st_code state dt_code district block11 bk_code11 merge_bk merge_bk11
sort st_code dt_code block11
replace state = state[_n-1] if state=="" & st_code==st_code[_n-1]
replace state = state[_n+1] if state=="" & st_code==st_code[_n+1]
replace district = district[_n-1] if district=="" & dt_code==dt_code[_n-1]
replace district = district[_n+1] if district=="" & dt_code==dt_code[_n+1]
duplicates drop 

  // Code to iterate to macth PCA 2011 block names (commented out after iterating)
/*
keep if merge_bk11<3 & merge_bk!=3
drop if block11==""
gen block_name_merge = ""  // create field for merge name, to go back and replace when opening schools dataset
gen q = `"""'
*/
/*
*Iterate 1x to correct blocks that are 1-2 letters off
gen block_pca_above = block11[_n-1] if merge_bk11[_n-1]==2
gen block_pca_below = block11[_n+1] if merge_bk11[_n+1]==2
strdist block11 block_pca_above if merge_bk11==1, gen(dist_above)
strdist block11 block_pca_below if merge_bk11==1, gen(dist_below)
br block11 block_pca_above dist_above if dist_above<3
br block11 block_pca_below dist_below if dist_below<3
replace block_name_merge = block_pca_above if merge_bk11==1 & merge_bk11[_n-1]==2 & dist_above<3 & dist_below>3 & state==state[_n-1] & district==district[_n-1] 
replace block_name_merge = block_pca_below if merge_bk11==1 & merge_bk11[_n+1]==2 & dist_below<3 & dist_above>3 & state==state[_n+1] & district==district[_n+1] 
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block11 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block11,-1)!="I" & word(block11,-1)!="II" & word(block11,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/
/*
*Iterate 1x to correct blocks that have a matching word
gen block_pca_above = block11[_n-1] if merge_bk11[_n-1]==2
gen block_pca_below = block11[_n+1] if merge_bk11[_n+1]==2
gen block_name_merge_above = block_pca_above if merge_bk11==1 & merge_bk11[_n-1]==2 & word(block11,1)==word(block_pca_above,1) & state==state[_n-1] & district==district[_n-1] 
gen block_name_merge_below = block_pca_below if merge_bk11==1 & merge_bk11[_n+1]==2 & word(block11,1)==word(block_pca_below,1) & state==state[_n+1] & district==district[_n+1] 
br state district block11 block_pca* block_name_merge_* if block_name_merge_above!="" | block_name_merge_below!=""
replace block_name_merge = block_name_merge_above if block_name_merge=="" & word(block_name_merge_above,-1)!="I" & word(block_name_merge_above,-1)!="II" & word(block_name_merge_above,-1)!="III" & word(block_name_merge_above,-1)!="WEST" & word(block_name_merge_above,-1)!="EAST" & word(block_name_merge_above,-1)!="SOUTH" & word(block_name_merge_above,-1)!="NORTH" & word(block11,-1)!="I" & word(block11,-1)!="II" & word(block11,-1)!="III" & word(block11,-1)!="WEST" & word(block11,-1)!="EAST" & word(block11,-1)!="SOUTH" & word(block11,-1)!="NORTH"  
replace block_name_merge = block_name_merge_below if block_name_merge=="" & word(block_name_merge_below,-1)!="I" & word(block_name_merge_below,-1)!="II" & word(block_name_merge_below,-1)!="III" & word(block_name_merge_below,-1)!="WEST" & word(block_name_merge_below,-1)!="EAST" & word(block_name_merge_below,-1)!="SOUTH" & word(block_name_merge_below,-1)!="NORTH" & word(block11,-1)!="I" & word(block11,-1)!="II" & word(block11,-1)!="III" & word(block11,-1)!="WEST" & word(block11,-1)!="EAST" & word(block11,-1)!="SOUTH" & word(block11,-1)!="NORTH"  
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block11 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block11,-1)!="I" & word(block11,-1)!="II" & word(block11,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/

drop if merge_bk11==2
duplicates drop
rename block11 block
replace bk_code11 = . if block=="SIRPUR" & district=="ADILABAD" & state=="ANDHRA PRADESH"
merge m:m state st_code district dt_code block using "$schools/schools_ALL_for_merge.dta", nogen
order st_code state dt_code district block bk_code_pca bk_code11
sort  st_code state dt_code district block bk_code_pca bk_code11
save "$schools/schools_ALL_for_merge.dta", replace
}
  ***

	// For remaining unmatched, try Concordance 2001 block names
{
use "$schools/schools_ALL_for_merge.dta", clear 
keep st_code state dt_code district block merge*
rename block block_2001
duplicates drop
merge 1:m st_code state dt_code district block_2001 using "$smerge/names_for_merge.dta", gen(merge_bkconc01)
keep st_code state dt_code district block_2001 bk_code_conc01 merge_bk merge_bk11 merge_bkconc01
sort st_code dt_code block_2001
replace state = state[_n-1] if state=="" & st_code==st_code[_n-1]
replace state = state[_n+1] if state=="" & st_code==st_code[_n+1]
replace district = district[_n-1] if district=="" & dt_code==dt_code[_n-1]
replace district = district[_n+1] if district=="" & dt_code==dt_code[_n+1]
duplicates drop 

  // Code to iterate to macth 2001 Concordance block names (commented out after iterating)
/*
keep if merge_bkconc01<3 & merge_bk!=3 & merge_bk11!=3
drop if block_2001==""
gen block_name_merge = ""  // create field for merge name, to go back and replace when opening schools dataset
gen q = `"""'
*/
/*
*Iterate 1x to correct blocks that are 1-2 letters off
gen block_pca_above = block_2001[_n-1] if merge_bkconc01[_n-1]==2
gen block_pca_below = block_2001[_n+1] if merge_bkconc01[_n+1]==2
strdist block_2001 block_pca_above if merge_bkconc01==1, gen(dist_above)
strdist block_2001 block_pca_below if merge_bkconc01==1, gen(dist_below)
br block_2001 block_pca_above dist_above if dist_above<3
br block_2001 block_pca_below dist_below if dist_below<3
replace block_name_merge = block_pca_above if merge_bkconc01==1 & merge_bkconc01[_n-1]==2 & dist_above<3 & dist_below>3 & state==state[_n-1] & district==district[_n-1] 
replace block_name_merge = block_pca_below if merge_bkconc01==1 & merge_bkconc01[_n+1]==2 & dist_below<3 & dist_above>3 & state==state[_n+1] & district==district[_n+1] 
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block_2001 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block_2001,-1)!="I" & word(block_2001,-1)!="II" & word(block_2001,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/
/*
*Iterate 0x to correct blocks that have a matching word
gen block_pca_above = block_2001[_n-1] if merge_bkconc01[_n-1]==2
gen block_pca_below = block_2001[_n+1] if merge_bkconc01[_n+1]==2
gen block_name_merge_above = block_pca_above if merge_bkconc01==1 & merge_bkconc01[_n-1]==2 & word(block_2001,1)==word(block_pca_above,1) & state==state[_n-1] & district==district[_n-1] 
gen block_name_merge_below = block_pca_below if merge_bkconc01==1 & merge_bkconc01[_n+1]==2 & word(block_2001,1)==word(block_pca_below,1) & state==state[_n+1] & district==district[_n+1] 
br state district block_2001 block_pca* block_name_merge_* if block_name_merge_above!="" | block_name_merge_below!=""
replace block_name_merge = block_name_merge_above if block_name_merge=="" & word(block_name_merge_above,-1)!="I" & word(block_name_merge_above,-1)!="II" & word(block_name_merge_above,-1)!="III" & word(block_name_merge_above,-1)!="WEST" & word(block_name_merge_above,-1)!="EAST" & word(block_name_merge_above,-1)!="SOUTH" & word(block_name_merge_above,-1)!="NORTH" & word(block_2001,-1)!="I" & word(block_2001,-1)!="II" & word(block_2001,-1)!="III" & word(block_2001,-1)!="WEST" & word(block_2001,-1)!="EAST" & word(block_2001,-1)!="SOUTH" & word(block_2001,-1)!="NORTH"  
replace block_name_merge = block_name_merge_below if block_name_merge=="" & word(block_name_merge_below,-1)!="I" & word(block_name_merge_below,-1)!="II" & word(block_name_merge_below,-1)!="III" & word(block_name_merge_below,-1)!="WEST" & word(block_name_merge_below,-1)!="EAST" & word(block_name_merge_below,-1)!="SOUTH" & word(block_name_merge_below,-1)!="NORTH" & word(block_2001,-1)!="I" & word(block_2001,-1)!="II" & word(block_2001,-1)!="III" & word(block_2001,-1)!="WEST" & word(block_2001,-1)!="EAST" & word(block_2001,-1)!="SOUTH" & word(block_2001,-1)!="NORTH"  
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block_2001 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block_2001,-1)!="I" & word(block_2001,-1)!="II" & word(block_2001,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/

drop if merge_bkconc01==2
duplicates drop
rename block_2001 block
replace bk_code_conc01 = . if block=="SIRPUR" & district=="ADILABAD" & state=="ANDHRA PRADESH"
merge m:m state st_code district dt_code block using "$schools/schools_ALL_for_merge.dta", nogen
order st_code state dt_code district block bk_code_pca bk_code11 bk_code_conc01
sort  st_code state dt_code district block bk_code_pca bk_code11 bk_code_conc01
save "$schools/schools_ALL_for_merge.dta", replace
}
***

	// For remaining unmatched, try Concordance 2011 block names
{
use "$schools/schools_ALL_for_merge.dta", clear 
keep st_code state dt_code district block merge*
rename block block_2011
duplicates drop
merge 1:m st_code state dt_code district block_2011 using "$smerge/names_for_merge.dta", gen(merge_bkconc11)
keep st_code state dt_code district block_2011 bk_code_conc11 merge_bk merge_bk11 merge_bkconc01 merge_bkconc11
sort st_code dt_code block_2011
replace state = state[_n-1] if state=="" & st_code==st_code[_n-1]
replace state = state[_n+1] if state=="" & st_code==st_code[_n+1]
replace district = district[_n-1] if district=="" & dt_code==dt_code[_n-1]
replace district = district[_n+1] if district=="" & dt_code==dt_code[_n+1]
duplicates drop 

  // Code to iterate to macth 2011 Concordance block names (commented out after iterating)
/*
keep if merge_bkconc11<3 & merge_bk!=3 & merge_bk11!=3 & merge_bkconc01!=3
drop if block_2011==""
gen block_name_merge = ""  // create field for merge name, to go back and replace when opening schools dataset
gen q = `"""'
*/
/*
*Iterate 1x to correct blocks that are 1-2 letters off
gen block_pca_above = block_2011[_n-1] if merge_bkconc11[_n-1]==2
gen block_pca_below = block_2011[_n+1] if merge_bkconc11[_n+1]==2
strdist block_2011 block_pca_above if merge_bkconc11==1, gen(dist_above)
strdist block_2011 block_pca_below if merge_bkconc11==1, gen(dist_below)
br block_2011 block_pca_above dist_above if dist_above<3
br block_2011 block_pca_below dist_below if dist_below<3
replace block_name_merge = block_pca_above if merge_bkconc11==1 & merge_bkconc11[_n-1]==2 & dist_above<3 & dist_below>3 & state==state[_n-1] & district==district[_n-1] 
replace block_name_merge = block_pca_below if merge_bkconc11==1 & merge_bkconc11[_n+1]==2 & dist_below<3 & dist_above>3 & state==state[_n+1] & district==district[_n+1] 
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block_2011 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block_2011,-1)!="I" & word(block_2011,-1)!="II" & word(block_2011,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/
/*
*Iterate 1x to correct blocks that have a matching word
gen block_pca_above = block_2011[_n-1] if merge_bkconc11[_n-1]==2
gen block_pca_below = block_2011[_n+1] if merge_bkconc11[_n+1]==2
gen block_name_merge_above = block_pca_above if merge_bkconc11==1 & merge_bkconc11[_n-1]==2 & word(block_2011,1)==word(block_pca_above,1) & state==state[_n-1] & district==district[_n-1] 
gen block_name_merge_below = block_pca_below if merge_bkconc11==1 & merge_bkconc11[_n+1]==2 & word(block_2011,1)==word(block_pca_below,1) & state==state[_n+1] & district==district[_n+1] 
br state district block_2011 block_pca* block_name_merge_* if block_name_merge_above!="" | block_name_merge_below!=""
replace block_name_merge = block_name_merge_above if block_name_merge=="" & word(block_name_merge_above,-1)!="I" & word(block_name_merge_above,-1)!="II" & word(block_name_merge_above,-1)!="III" & word(block_name_merge_above,-1)!="WEST" & word(block_name_merge_above,-1)!="EAST" & word(block_name_merge_above,-1)!="SOUTH" & word(block_name_merge_above,-1)!="NORTH" & word(block_2011,-1)!="I" & word(block_2011,-1)!="II" & word(block_2011,-1)!="III" & word(block_2011,-1)!="WEST" & word(block_2011,-1)!="EAST" & word(block_2011,-1)!="SOUTH" & word(block_2011,-1)!="NORTH"  
replace block_name_merge = block_name_merge_below if block_name_merge=="" & word(block_name_merge_below,-1)!="I" & word(block_name_merge_below,-1)!="II" & word(block_name_merge_below,-1)!="III" & word(block_name_merge_below,-1)!="WEST" & word(block_name_merge_below,-1)!="EAST" & word(block_name_merge_below,-1)!="SOUTH" & word(block_name_merge_below,-1)!="NORTH" & word(block_2011,-1)!="I" & word(block_2011,-1)!="II" & word(block_2011,-1)!="III" & word(block_2011,-1)!="WEST" & word(block_2011,-1)!="EAST" & word(block_2011,-1)!="SOUTH" & word(block_2011,-1)!="NORTH"  
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block_2011 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block_2011,-1)!="I" & word(block_2011,-1)!="II" & word(block_2011,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/

drop if merge_bkconc11==2
duplicates drop
rename block_2011 block
replace bk_code_conc11 = . if block=="SIRPUR" & district=="ADILABAD" & state=="ANDHRA PRADESH"
merge m:m state st_code district dt_code block using "$schools/schools_ALL_for_merge.dta", nogen
order st_code state dt_code district block bk_code_pca bk_code11 bk_code_conc01 bk_code_conc11
sort  st_code state dt_code district block bk_code_pca bk_code11 bk_code_conc01 bk_code_conc11
save "$schools/schools_ALL_for_merge.dta", replace
}
  ***

  // For remaining unmatched, try VD 2011 block1 names
{
use "$schools/schools_ALL_for_merge.dta", clear 
keep st_code state dt_code district block merge*
rename block block1_vd11
duplicates drop
merge 1:m st_code state dt_code district block1_vd11 using "$smerge/names_for_merge.dta", gen(merge_bk1vd11)
keep st_code state dt_code district block1_vd11 bk_code1_vd11 merge_bk merge_bk11 merge_bkconc01 merge_bkconc11 merge_bk1vd11
sort st_code dt_code block1_vd11
replace state = state[_n-1] if state=="" & st_code==st_code[_n-1]
replace state = state[_n+1] if state=="" & st_code==st_code[_n+1]
replace district = district[_n-1] if district=="" & dt_code==dt_code[_n-1]
replace district = district[_n+1] if district=="" & dt_code==dt_code[_n+1]
duplicates drop 

  // Code to iterate to macth VD 2011 block1 names (commented out after iterating)
/*
keep if merge_bk1vd11<3 & merge_bk!=3 & merge_bk11!=3 & merge_bkconc01!=3 & merge_bkconc11!=3
drop if block1_vd11==""
gen block_name_merge = ""  // create field for merge name, to go back and replace when opening schools dataset
gen q = `"""'
*/
/*
*Iterate 2x to correct blocks that are 1-2 letters off
gen block_pca_above = block1_vd11[_n-1] if merge_bk1vd11[_n-1]==2
gen block_pca_below = block1_vd11[_n+1] if merge_bk1vd11[_n+1]==2
strdist block1_vd11 block_pca_above if merge_bk1vd11==1, gen(dist_above)
strdist block1_vd11 block_pca_below if merge_bk1vd11==1, gen(dist_below)
br block1_vd11 block_pca_above dist_above if dist_above<3
br block1_vd11 block_pca_below dist_below if dist_below<3
replace block_name_merge = block_pca_above if merge_bk1vd11==1 & merge_bk1vd11[_n-1]==2 & dist_above<3 & dist_below>3 & state==state[_n-1] & district==district[_n-1] 
replace block_name_merge = block_pca_below if merge_bk1vd11==1 & merge_bk1vd11[_n+1]==2 & dist_below<3 & dist_above>3 & state==state[_n+1] & district==district[_n+1] 
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block1_vd11 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block1_vd11,-1)!="I" & word(block1_vd11,-1)!="II" & word(block1_vd11,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/
/*
*Iterate 1x to correct blocks that have a matching word
gen block_pca_above = block1_vd11[_n-1] if merge_bk1vd11[_n-1]==2
gen block_pca_below = block1_vd11[_n+1] if merge_bk1vd11[_n+1]==2
gen block_name_merge_above = block_pca_above if merge_bk1vd11==1 & merge_bk1vd11[_n-1]==2 & word(block1_vd11,1)==word(block_pca_above,1) & state==state[_n-1] & district==district[_n-1] 
gen block_name_merge_below = block_pca_below if merge_bk1vd11==1 & merge_bk1vd11[_n+1]==2 & word(block1_vd11,1)==word(block_pca_below,1) & state==state[_n+1] & district==district[_n+1] 
br state district block1_vd11 block_pca* block_name_merge_* if block_name_merge_above!="" | block_name_merge_below!=""
replace block_name_merge = block_name_merge_above if block_name_merge=="" & word(block_name_merge_above,-1)!="I" & word(block_name_merge_above,-1)!="II" & word(block_name_merge_above,-1)!="III" & word(block_name_merge_above,-1)!="WEST" & word(block_name_merge_above,-1)!="EAST" & word(block_name_merge_above,-1)!="SOUTH" & word(block_name_merge_above,-1)!="NORTH" & word(block1_vd11,-1)!="I" & word(block1_vd11,-1)!="II" & word(block1_vd11,-1)!="III" & word(block1_vd11,-1)!="WEST" & word(block1_vd11,-1)!="EAST" & word(block1_vd11,-1)!="SOUTH" & word(block1_vd11,-1)!="NORTH"  
replace block_name_merge = block_name_merge_below if block_name_merge=="" & word(block_name_merge_below,-1)!="I" & word(block_name_merge_below,-1)!="II" & word(block_name_merge_below,-1)!="III" & word(block_name_merge_below,-1)!="WEST" & word(block_name_merge_below,-1)!="EAST" & word(block_name_merge_below,-1)!="SOUTH" & word(block_name_merge_below,-1)!="NORTH" & word(block1_vd11,-1)!="I" & word(block1_vd11,-1)!="II" & word(block1_vd11,-1)!="III" & word(block1_vd11,-1)!="WEST" & word(block1_vd11,-1)!="EAST" & word(block1_vd11,-1)!="SOUTH" & word(block1_vd11,-1)!="NORTH"  
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block1_vd11 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block1_vd11,-1)!="I" & word(block1_vd11,-1)!="II" & word(block1_vd11,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/

drop if merge_bk1vd11==2
duplicates drop
rename block1_vd11 block
replace bk_code1_vd11 = . if block=="SIRPUR" & district=="ADILABAD" & state=="ANDHRA PRADESH"
merge m:m state st_code district dt_code block using "$schools/schools_ALL_for_merge.dta", nogen
order st_code state dt_code district block bk_code_pca bk_code11 bk_code_conc01 bk_code_conc11 bk_code1_vd11
sort  st_code state dt_code district block bk_code_pca bk_code11 bk_code_conc01 bk_code_conc11 bk_code1_vd11
save "$schools/schools_ALL_for_merge.dta", replace
}
  ***

	// For remaining unmatched, try VD 2011 block2 names
{	
use "$schools/schools_ALL_for_merge.dta", clear 
keep st_code state dt_code district block merge*
rename block block2_vd11
duplicates drop
merge 1:m st_code state dt_code district block2_vd11 using "$smerge/names_for_merge.dta", gen(merge_bk2vd11)
keep st_code state dt_code district block2_vd11 bk_code2_vd11 merge_bk merge_bk11 merge_bkconc01 merge_bkconc11 merge_bk1vd11 merge_bk2vd11
sort st_code dt_code block2_vd11
replace state = state[_n-1] if state=="" & st_code==st_code[_n-1]
replace state = state[_n+1] if state=="" & st_code==st_code[_n+1]
replace district = district[_n-1] if district=="" & dt_code==dt_code[_n-1]
replace district = district[_n+1] if district=="" & dt_code==dt_code[_n+1]
duplicates drop 

  // Code to iterate to macth VD 2011 block2 names (commented out after iterating)
/*
keep if merge_bk2vd11<3 & merge_bk!=3 & merge_bk11!=3 & merge_bkconc01!=3 & merge_bkconc11!=3 & merge_bk1vd11!=3
drop if block2_vd11==""
gen block_name_merge = ""  // create field for merge name, to go back and replace when opening schools dataset
gen q = `"""'
*/
/*
*Iterate 3x to correct blocks that are 1-2 letters off
gen block_pca_above = block2_vd11[_n-1] if merge_bk2vd11[_n-1]==2
gen block_pca_below = block2_vd11[_n+1] if merge_bk2vd11[_n+1]==2
strdist block2_vd11 block_pca_above if merge_bk2vd11==1, gen(dist_above)
strdist block2_vd11 block_pca_below if merge_bk2vd11==1, gen(dist_below)
br block2_vd11 block_pca_above dist_above if dist_above<3
br block2_vd11 block_pca_below dist_below if dist_below<3
replace block_name_merge = block_pca_above if merge_bk2vd11==1 & merge_bk2vd11[_n-1]==2 & dist_above<3 & dist_below>3 & state==state[_n-1] & district==district[_n-1] 
replace block_name_merge = block_pca_below if merge_bk2vd11==1 & merge_bk2vd11[_n+1]==2 & dist_below<3 & dist_above>3 & state==state[_n+1] & district==district[_n+1] 
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block2_vd11 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block2_vd11,-1)!="I" & word(block2_vd11,-1)!="II" & word(block2_vd11,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/
/*
*Iterate 1x to correct blocks that have a matching word
gen block_pca_above = block2_vd11[_n-1] if merge_bk2vd11[_n-1]==2
gen block_pca_below = block2_vd11[_n+1] if merge_bk2vd11[_n+1]==2
gen block_name_merge_above = block_pca_above if merge_bk2vd11==1 & merge_bk2vd11[_n-1]==2 & word(block2_vd11,1)==word(block_pca_above,1) & state==state[_n-1] & district==district[_n-1] 
gen block_name_merge_below = block_pca_below if merge_bk2vd11==1 & merge_bk2vd11[_n+1]==2 & word(block2_vd11,1)==word(block_pca_below,1) & state==state[_n+1] & district==district[_n+1] 
br state district block2_vd11 block_pca* block_name_merge_* if block_name_merge_above!="" | block_name_merge_below!=""
replace block_name_merge = block_name_merge_above if block_name_merge=="" & word(block_name_merge_above,-1)!="I" & word(block_name_merge_above,-1)!="II" & word(block_name_merge_above,-1)!="III" & word(block_name_merge_above,-1)!="WEST" & word(block_name_merge_above,-1)!="EAST" & word(block_name_merge_above,-1)!="SOUTH" & word(block_name_merge_above,-1)!="NORTH" & word(block2_vd11,-1)!="I" & word(block2_vd11,-1)!="II" & word(block2_vd11,-1)!="III" & word(block2_vd11,-1)!="WEST" & word(block2_vd11,-1)!="EAST" & word(block2_vd11,-1)!="SOUTH" & word(block2_vd11,-1)!="NORTH"  
replace block_name_merge = block_name_merge_below if block_name_merge=="" & word(block_name_merge_below,-1)!="I" & word(block_name_merge_below,-1)!="II" & word(block_name_merge_below,-1)!="III" & word(block_name_merge_below,-1)!="WEST" & word(block_name_merge_below,-1)!="EAST" & word(block_name_merge_below,-1)!="SOUTH" & word(block_name_merge_below,-1)!="NORTH" & word(block2_vd11,-1)!="I" & word(block2_vd11,-1)!="II" & word(block2_vd11,-1)!="III" & word(block2_vd11,-1)!="WEST" & word(block2_vd11,-1)!="EAST" & word(block2_vd11,-1)!="SOUTH" & word(block2_vd11,-1)!="NORTH"  
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block2_vd11 + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & word(block_name_merge,-1)!="I" & word(block_name_merge,-1)!="II" & word(block_name_merge,-1)!="III" & word(block2_vd11,-1)!="I" & word(block2_vd11,-1)!="II" & word(block2_vd11,-1)!="III"
br if replace_text!="" // <-- copy-paste browse window into Step 2 and reiterate
*/

drop if merge_bk2vd11==2
duplicates drop
rename block2_vd11 block
replace bk_code2_vd11 = . if block=="SIRPUR" & district=="ADILABAD" & state=="ANDHRA PRADESH"
merge m:m state st_code district dt_code block using "$schools/schools_ALL_for_merge.dta", nogen
duplicates drop schv_id, force
order st_code state dt_code district block bk_code_pca bk_code11 bk_code_conc01 bk_code_conc11 bk_code1_vd11 bk_code2_vd11
sort  st_code state dt_code district block bk_code_pca bk_code11 bk_code_conc01 bk_code_conc11 bk_code1_vd11 bk_code2_vd11
save "$schools/schools_ALL_for_merge.dta", replace
}

}


********************************************************************************
********************************************************************************

** Step 4: Village matches, part I: Exact matches, where we know the block code
{
use "$smerge/names_for_merge.dta", clear
foreach v of varlist bk_code* {
  assert `v'>=0
	replace `v'=-1 if `v'==.
}
rename village village_pca
rename block block_pca

*Find exact merges on village name, for all block code & village name combos
foreach bk of varlist bk_code_pca bk_code2_vd11 bk_code11 bk_code_conc01 bk_code_conc11 bk_code1_vd11 {
	local bk_stub = subinstr(substr("`bk'",8,99),"_","",.)
	gen schv_id_`bk_stub' = .
	gen match_`bk_stub'_vi = ""
	foreach vi of varlist village_pca village_vd village11 village_conc01 village_conc11 village_vd11 {
		local vi_stub = subinstr(substr("`vi'",8,99),"_","",.)
		rename `vi' village
	  merge m:m st_code dt_code `bk' village using "$schools/schools_ALL_for_merge.dta", keep(1 3) keepusing(schv_id count_sch_id)
	  replace schv_id_`bk_stub' = schv_id if schv_id!=. & schv_id_`bk_stub'==. & _merge==3
		replace match_`bk_stub'_vi = match_`bk_stub'_vi + " `vi_stub'" if _merge==3 
		rename village `vi'
		drop schv_id _merge
	}
}

*Create unified village match field and merge in from Schools data
duplicates drop
egen schv_id_rowmin = rowmin(schv_id_pca schv_id_2vd11 schv_id_11 schv_id_conc01 schv_id_conc11 schv_id_1vd11)
egen schv_id_rowmax = rowmax(schv_id_pca schv_id_2vd11 schv_id_11 schv_id_conc01 schv_id_conc11 schv_id_1vd11)
egen schv_id_rowmin2 = rowmin(schv_id_pca schv_id_2vd11 schv_id_11 schv_id_conc01)
egen schv_id_rowmax2 = rowmax(schv_id_pca schv_id_2vd11 schv_id_11 schv_id_conc01)
egen schv_id_rowmin3 = rowmin(schv_id_pca schv_id_2vd11 schv_id_11)
egen schv_id_rowmax3 = rowmax(schv_id_pca schv_id_2vd11 schv_id_11)
egen schv_id_rowmean = rowmean(schv_id_pca schv_id_2vd11 schv_id_11 schv_id_conc01 schv_id_conc11 schv_id_1vd11)
gen schv_id = .
replace schv_id = schv_id_rowmin if schv_id==. & schv_id_rowmin==schv_id_rowmax & schv_id_rowmin!=. 
replace schv_id = schv_id_rowmin if schv_id==. & schv_id_rowmin2==schv_id_rowmax2 & schv_id_rowmin!=. 
replace schv_id = schv_id_rowmin if schv_id==. & schv_id_rowmin3==schv_id_rowmax3 & schv_id_rowmin!=.
replace schv_id = schv_id_rowmin if schv_id==. & schv_id_rowmin!=. & schv_id_rowmean-schv_id_rowmin<schv_id_rowmax-schv_id_rowmean
replace schv_id = schv_id_rowmax if schv_id==. & schv_id_rowmax!=. & schv_id_rowmean-schv_id_rowmin>schv_id_rowmax-schv_id_rowmean
foreach v of varlist schv_id_* {
	replace schv_id = `v' if `v'!=. & schv_id==.
}
merge m:1 schv_id using "$schools/schools_ALL_for_merge.dta", keep(1 3) keepusing(block village)
duplicates drop


*Remove duplicates, so a single PCA village doesn't match to multiple Schools data villages
duplicates t names_id, gen(dup1)
sort names_id

  // drop the few where there are just straight duplicates of both master and using identifiers
duplicates drop names_id schv_id, force

  // drop if there's match discrepancies within a row
gen todrop1 = 0
replace todrop1 = 1 if dup1>0 & names_id==names_id[_n-1] & (schv_id_rowmin2!=schv_id_rowmin | schv_id_rowmax2!=schv_id_rowmax) 
replace todrop1 = 1 if dup1>0 & names_id==names_id[_n+1] & (schv_id_rowmin2!=schv_id_rowmin | schv_id_rowmax2!=schv_id_rowmax) 
egen todrop1_min = min(todrop1), by(names_id)
drop if todrop1==1 & todrop1_min==0

  // drop if the other duplicate has no match discrepancies
gen todrop2 = 0
replace todrop2 = 1 if dup1>0 & names_id==names_id[_n-1] & schv_id[_n-1]==schv_id_rowmin[_n-1] & schv_id[_n-1]==schv_id_rowmax[_n-1]
replace todrop2 = 1 if dup1>0 & names_id==names_id[_n+1] & schv_id[_n+1]==schv_id_rowmin[_n+1] & schv_id[_n+1]==schv_id_rowmax[_n+1]
egen todrop2_min = min(todrop2), by(names_id)
drop if todrop2==1 & todrop2_min==0

  // drop if only the other duplicate has a block that matches
gen todrop3 = 0
replace todrop3 = 1 if dup1>0 & names_id==names_id[_n-1] & block!=block[_n-1] & schv_id[_n-1]==schv_id_rowmin[_n-1] & schv_id[_n-1]==schv_id_rowmax[_n-1]
replace todrop3 = 1 if dup1>0 & names_id==names_id[_n+1] & schv_id[_n+1]==schv_id_rowmin[_n+1] & schv_id[_n+1]==schv_id_rowmax[_n+1]
egen todrop3_min = min(todrop3), by(names_id)
drop if todrop3==1 & todrop3_min==0

  // keep the ones where the block agrees most often
gen block_match_count = block==block_pca
replace block_match_count = block_match_count + (block==block2_vd11)
replace block_match_count = block_match_count + (block==block11)
replace block_match_count = block_match_count + (block==block_2001)
replace block_match_count = block_match_count + (block==block_2011)
replace block_match_count = block_match_count + (block==block1_vd11)
drop if dup1>0 & names_id==names_id[_n-1] & block_match_count<block_match_count[_n-1]
drop if dup1>0 & names_id==names_id[_n+1] & block_match_count<block_match_count[_n+1]

  // for matches where block NEVER agrees -- reset schools data variables to zero (this should take care of remaining dups)
replace schv_id = . 	if _merge==3 & block_match_count==0
replace block = "" 		if _merge==3 & block_match_count==0
replace village = "" 	if _merge==3 & block_match_count==0

duplicates t names_id if schv_id!=., gen(dup1_check)
assert dup1_check==0 if schv_id!=.

*Remove duplicates, so a single schools data village doesn't match to multiple PCA villages
duplicates t schv_id, gen(dup2)
replace dup2 = . if schv_id==.
sort schv_id
gen dup2_keep = 0

  // trust the schv_id that matched the most times
gen match_count = schv_id_pca!=.
replace match_count = match_count + (schv_id_2vd11!=.)
replace match_count = match_count + (schv_id_11!=.)
replace match_count = match_count + (schv_id_conc01!=.)
replace match_count = match_count + (schv_id_conc11!=.)
replace match_count = match_count + (schv_id_1vd11!=.)
gen match_all = trim(itrim(match_pca_vi + " " + match_2vd11_vi + " " + match_11_vi + " " + match_conc01_vi + " " + match_conc11_vi + " " + match_1vd11_vi))
egen match_count2 = noccur(match_all), string(" ")
egen match_count_max = max(match_count), by(schv_id)
egen match_count_min = min(match_count), by(schv_id)
egen match_count2_max = max(match_count2), by(schv_id)
egen match_count2_min = min(match_count2), by(schv_id)
replace dup2_keep = 1 if dup2>0 & dup2!=. & match_count2==match_count2_max & match_count2>match_count2_min
replace dup2_keep = 1 if dup2>0 & dup2!=. & match_count==match_count_max & match_count>match_count_min
egen dup2_keep_max = max(dup2_keep), by(schv_id)

  // i'm content to live with these dups for now, they're less than 4% of matches, and dupes will get sorted later
*br if dup2>0 & dup2<. & dup2_keep_max==0
replace dup2_keep = 1 if dup2>0 & dup2!=. & dup2_keep_max==0

  // reset schv_id and schools data variables to blanks for the weaker of the duplicate matches
replace schv_id = . 			if dup2>0 & dup2!=. & dup2_keep==0
replace block = "" 				if dup2>0 & dup2!=. & dup2_keep==0
replace village = "" 			if dup2>0 & dup2!=. & dup2_keep==0
replace count_sch_id = . 	if dup2>0 & dup2!=. & dup2_keep==0
drop dup1* todrop1* todrop2* todrop3* _merge dup2* schv_id_row*  match_all match_count2* match_count_*
rename block blockS
rename village villageS

*Drop duplicates and bad matches, confirm a(n almost) 1-1 match
duplicates drop
duplicates r schv_id
duplicates r names_id


*Split "names" dataset into matched and unmatched villages
preserve
keep if schv_id!=.
save "$smerge/pca_2001_names_merges_all_temp_matched.dta", replace
restore
keep if schv_id==.
drop schv_id_pca-match_count
duplicates drop  
save "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", replace


*Split schools dataset into matched and unmatched villages
use "$schools/schools_ALL_for_merge.dta", clear
merge 1:m schv_id using "$smerge/pca_2001_names_merges_all_temp_matched.dta", keepusing(schv_id)
duplicates drop 
assert _merge!=2
preserve
keep if _merge==3
drop _merge
save "$schools/school_census_for_merge_temp_matched.dta", replace
restore
unique schv_id if _merge==1
merge 1:m schv_id using "$schools/schools_ALL_for_merge_all.dta", gen(m_schv9_id) keepusing(schv9_id) keep(1 3)
assert m_schv9_id==3
egen _merge_max = max(_merge), by(schv9_id)
keep if _merge==1 & _merge_max==1
drop _merge m_schv9_id _merge_max schv9_id
duplicates drop
unique schv_id
save "$schools/school_census_for_merge_temp_unmatched.dta", replace
}



********************************************************************************
********************************************************************************

** Step 5: Village matches, part II: Exact matches, where we don't know the block code (being conservative!)
{
*Grab villages without block matches from unmatched
use "$schools/school_census_for_merge_temp_unmatched.dta", clear
keep if bk_code_pca==. & bk_code11==. & bk_code_conc01==. & bk_code_conc11==. & bk_code1_vd11==. & bk_code2_vd11==.
assert dt_code!=.
save "$schools/school_census_for_merge_temp_unmatched_nobk.dta", replace

*Merge on just st_code, dt_code, and village hame
use "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", clear
gen schv_id_nobk = .
gen match_nobk_vi = ""
foreach vi of varlist village_pca village_vd village11 village_conc01 village_conc11 village_vd11 {
	local vi_stub = subinstr(substr("`vi'",8,99),"_","",.)
	rename `vi' village
  merge m:m st_code dt_code village using "$schools/school_census_for_merge_temp_unmatched_nobk.dta", keep(1 3) keepusing(schv_id count_sch_id)
  replace schv_id_nobk = schv_id if schv_id!=. & schv_id_nobk==. & _merge==3
	replace match_nobk_vi = match_nobk_vi + " `vi_stub'" if _merge==3 
	rename village `vi'
	drop schv_id _merge
}
duplicates drop
rename schv_id_nobk schv_id 
merge m:1 schv_id using "$schools/school_census_for_merge_temp_unmatched_nobk.dta", keep(1 3) keepusing(block village)
duplicates drop

*Remove duplicates, so a single PCA village doesn't match to multiple schools data villages
duplicates t names_id, gen(dup1)
sort names_id

  // drop the few where there are just straight duplicates of both master and using identifiers
duplicates drop names_id schv_id, force

 // try to match a few more block names (normally comment this section out)
/*
keep block* district dt_code state st_code schv_id
keep if schv_id!=.
gen id = _n
collapse (count) id, by(block* district dt_code state st_code)
gsort -id

foreach v of varlist block_pca block2_vd11 block11 block_2001 block_2011 block1_vd11 {
  strdist block `v' if `v'!="", gen(d_`v')
}
egen d_min = rowmin(d_*)
gen block_name_merge = ""
foreach v of varlist block_pca block2_vd11 block11 block_2001 block_2011 block1_vd11 {
  replace block_name_merge = `v' if block_name_merge=="" & d_`v'==d_min
}
gen q = `"""'
gen replace_text = "replace block = " + q + block_name_merge + q + " if block==" + q + block + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & id>=100
br if replace_text!=""
gen replace_text2= "replace block = " + q + block_name_merge + q + " if block==" + q + block + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & id>=50
br if replace_text=="" & replace_text2!=""
gen replace_text3= "replace block = " + q + block_name_merge + q + " if block==" + q + block + q + " & district==" + q + district + q + " & state==" + q + state + q if block_name_merge!="" & substr(block_name_merge,1,length(block))==block
br if replace_text=="" & replace_text2=="" & replace_text3!="" & block!=block_name_merge & block!="" & block_name_merge!="" // <-- copy-paste browse window into Step 2 and reiterate

sum id 
di r(sum) // 10683 <-- make sure that by correcting these block spellings, you have fewer unmatched villages!
sum id if replace_text=="" & replace_text2=="" & replace_text3!="" & block!=block_name_merge & block!="" & block_name_merge!=""
di r(sum) // 24 <-- make sure that by correcting these block spellings, you have fewer unmatched villages!
*/

*Create flag for names matches to keep
duplicates t names_id, gen(dup2)
egen match_count = count(names_id), by(block* district dt_code state st_code)
gen keep_flag = 0
replace keep_flag = 1 if _merge==3 & match_count>=20 & dup2==0
replace schv_id = . 		if _merge==3 & keep_flag==0
replace block = "" 		if _merge==3 & keep_flag==0
replace village = "" 	if _merge==3 & keep_flag==0
foreach v of varlist match_count {
  replace `v' = .	if _merge==3 & keep_flag==0
}
duplicates drop
duplicates r names_id


*Remove duplicates, so a single schools data village doesn't match to multiple PCA villages
duplicates t schv_id, gen(dup3)
replace dup3 = . if schv_id==.
sort schv_id

  // i'm content to live with these dups for now, they're less than 4% of matches
*br if dup3>0 & dup3<.
gen dup3_keep = 0
replace dup3_keep = 1 if dup3>0 & dup3!=. 

  // reset schv_id and schools data variables to blanks for the weaker of the duplicate matches
replace schv_id = . 			if dup3>0 & dup3!=. & dup3_keep==0
replace block = "" 				if dup3>0 & dup3!=. & dup3_keep==0
replace village = "" 			if dup3>0 & dup3!=. & dup3_keep==0
replace count_sch_id = . 	if dup3>0 & dup3!=. & dup3_keep==0
gen schv_id_nobk = schv_id
drop dup1* dup2* dup3* keep* match_count _merge match_count // _merge

rename block blockS
rename village villageS

*Drop duplicates and bad matches, confirm a(n almost) 1-1 match
duplicates drop
duplicates r schv_id
duplicates r names_id

*Update "names" matched and unmatched datasets
preserve
keep if schv_id!=.
append using "$smerge/pca_2001_names_merges_all_temp_matched.dta"
order pca01_id st_code-names_id schv_id schv_id_pca-match_1vd11_vi schv_id_nobk match_nobk_vi 
save "$smerge/pca_2001_names_merges_all_temp_matched.dta", replace
restore
keep if schv_id==.
drop schv_id-schv_id_nobk
duplicates drop
save "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", replace


*Split schools dataset into matched and unmatched villages
use "$schools/schools_ALL_for_merge.dta", clear
merge 1:m schv_id using "$smerge/pca_2001_names_merges_all_temp_matched.dta", keepusing(schv_id)
duplicates drop 
assert _merge!=2
preserve
keep if _merge==3
drop _merge
save "$schools/school_census_for_merge_temp_matched.dta", replace
restore
unique schv_id if _merge==1
merge 1:m schv_id using "$schools/schools_ALL_for_merge_all.dta", gen(m_schv9_id) keepusing(schv9_id) keep(1 3)
assert m_schv9_id==3
egen _merge_max = max(_merge), by(schv9_id)
keep if _merge==1 & _merge_max==1
drop _merge m_schv9_id _merge_max schv9_id
duplicates drop
unique schv_id
save "$schools/school_census_for_merge_temp_unmatched.dta", replace

}

  // send these unmatched files to the server for a fuzzy (reclink) merge
  // "merge_schools_fuzzy.do", Steps 1-4

********************************************************************************
********************************************************************************

** Step 6: Village matches, part III: Process reclink matches from server
  // get reclink merge results from server
{
use "$smerge/pca_2001_names_matched_reclink.dta", clear
*br names_id schv_id blockS-pop_diff11_3 fscore_pca fscore_11 fscore_2vd11 fuzzy_pca fuzzy_11 fuzzy_2vd11
egen fscore = rowmin(fscore_pca fscore_11 fscore_2vd11)
gen fmatch_bk = "pca" if fuzzy_pca!=""
replace fmatch_bk = fmatch_bk + " 11" if fuzzy_11!=""
replace fmatch_bk = fmatch_bk + " 2vd11" if fuzzy_2vd11!=""
gen fmatch_vi = fuzzy_pca if fuzzy_pca!=""
replace fmatch_vi = fmatch_vi + " " + fuzzy_11 if fuzzy_11!="" & fuzzy_11!=fmatch_vi
replace fmatch_vi = fmatch_vi + " " + fuzzy_2vd11 if fuzzy_2vd11!="" & fuzzy_2vd11!=fmatch_vi
replace fmatch_bk = trim(itrim(fmatch_bk))
replace fmatch_vi = trim(itrim(fmatch_vi))
drop fscore_pca fscore_11 fscore_2vd11 fuzzy_pca fuzzy_11 fuzzy_2vd11
drop if fscore<0.97 // make sure to eyeball this and confirm that 0.97 is sufficiently conservative!

*Resolve the double and triple matches
sort names_id schv_id fmatch_bk fmatch_vi
egen group_temp = group(names_id schv_id)
gen fmatch = fmatch_bk if group_temp>group_temp[_n-1] | _n==1
replace fmatch = fmatch + " " + fmatch_bk[_n+1] if group_temp>group_temp[_n-1] & group_temp==group_temp[_n+1]
replace fmatch = fmatch + " " + fmatch_bk[_n+2] if group_temp>group_temp[_n-1] & group_temp==group_temp[_n+1] & group_temp==group_temp[_n+2]
replace fmatch = subinstr(fmatch,"11 pca","pca 11", .)
replace fmatch = fmatch + " (" + fmatch_vi if fmatch!=""
replace fmatch = fmatch + " " + fmatch_vi[_n+1] if fmatch!="" & group_temp==group_temp[_n+1] & fmatch_vi[_n+1]!=fmatch_vi
replace fmatch = fmatch + " " + fmatch_vi[_n+2] if fmatch!="" & group_temp==group_temp[_n+2] & fmatch_vi!=fmatch_vi[_n+2] & fmatch_vi[_n+1]!=fmatch_vi[_n+2]
replace fmatch = fmatch + ")" if fmatch!=""
drop if fmatch==""
assert group_temp==_n
drop fmatch_bk fmatch_vi group_temp

*Remove duplicates, so a single PCA village doesn't match to multiple schools villages
duplicates t names_id, gen(dup1)
sort names_id
gen fvil = "_" + subinstr(subinstr(word(fmatch,-1),"(","",.),")","",.)
gen fvillage = ""
rename village11 village_11
foreach v of newlist _pca _vd _11 _conc01 _conc11 _vd11 {
  replace fvillage = village`v' if fvil=="`v'"
}
rename village_11 village11

  // drop based on string distance of village names and fscore (combined)
strdist fvillage village, gen(d_vill)
egen d_vill_min = min(d_vill), by(names_id)
egen fscore_max = max(fscore), by(names_id)
drop if dup1>0 & (names_id==names_id[_n-1] | names_id==names_id[_n+1]) & d_vill>d_vill_min & fscore<fscore_max 

*Remove duplicates, so a single schools data village doesn't match to multiple PCA villages
duplicates t schv_id, gen(dup2)
sort schv_id
gen dup2_keep = 0

  // drop based on string distance and fscore (combined)
egen d_vill_min2 = min(d_vill), by(schv_id)
egen fscore_max2 = max(fscore), by(schv_id)
replace dup2_keep = 1 if dup2>0 & dup2!=. & d_vill==d_vill_min2 & fscore==fscore_max2
egen dup2_keep_max = max(dup2_keep), by(schv_id)

  // drop based on fscore (combined)
replace dup2_keep = 1 if dup2>0 & dup2!=. & dup2_keep_max==0 & fscore==fscore_max2
egen dup2_keep_max2 = max(dup2_keep), by(schv_id)

  // i'm content to live with these dups for now, and take them out of circulation
*br if dup2>0 & dup2<. & dup2_keep_max2==0
replace dup2_keep = 1 if dup2>0 & dup2!=. & dup2_keep_max2==0

  // drop weaker of the schv_id duplicate matches and prep for merging
drop if dup2>0 & dup2!=. & dup2_keep==0
keep names_id schv_id block village nschools count_sch_id fscore fmatch fvill fvillage d_vill
rename block blockS
rename village villageS

*Append to matched dataset and remove from unmatched dataset
preserve
merge m:1 names_id using "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", keep(3) nogen
append using "$smerge/pca_2001_names_merges_all_temp_matched.dta"
order pca01_id names_id schv_id blockS-count_sch_id st_code-match_count fmatch fscore fvillage d_vill
compress
save "$smerge/pca_2001_names_merges_all_temp_matched.dta", replace
restore
keep names_id 
duplicates drop  
merge 1:1 names_id using "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", keep(2) nogen
save "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", replace

*Split hab census dataset into matched and unmatched villages
use "$schools/schools_ALL_for_merge.dta", clear
merge 1:m schv_id using "$smerge/pca_2001_names_merges_all_temp_matched.dta", keepusing(schv_id)
duplicates drop 
assert _merge!=2
preserve
keep if _merge==3
drop _merge
save "$schools/school_census_for_merge_temp_matched.dta", replace
restore
unique schv_id if _merge==1
merge 1:m schv_id using "$schools/schools_ALL_for_merge_all.dta", gen(m_schv9_id) keepusing(schv9_id) keep(1 3)
assert m_schv9_id==3
egen _merge_max = max(_merge), by(schv9_id)
keep if _merge==1 & _merge_max==1
drop _merge m_schv9_id _merge_max schv9_id
duplicates drop
unique schv_id
save "$schools/school_census_for_merge_temp_unmatched.dta", replace

}	
  // send remaining unmatched files to the server for a fuzzy (masala) merge (within matched blocks)
  // "merge_schools_fuzzy.do", Step 5

********************************************************************************
********************************************************************************

** Step 7: Village matches, part IV: Process masala matches from server (within matched blocks)
  // get masala merge results from server
{
*Drop duplicates from MMout_all, "reshape", and calculate M-L distance
use "$schools/MMout_all_bk.dta", clear
sort  names_id schv_id bk vi
*br names_id schv_id bk vi

  // drop MM non-block matches, if that same names_id has a block match
*gen no_bk = bk=="nobk" | bk=="nobk11"
*egen no_bk_min = min(no_bk), by(names_id schv_id)  
*drop if no_bk==1 & no_bk_min==0

  // "reshape" bk and vi by hand
egen group1 = group(names_id schv_id)
sort group1 bk vi
gen bk_MM_matches = ""
replace bk_MM_matches = bk if group1>group1[_n-1] | _n==1
forvalues i =1/4 {
  replace bk_MM_matches = bk_MM_matches + " " + bk[_n+`i'] if bk_MM_matches!="" & group1[_n+`i']==group1[_n] 
}
gen vi_MM_matches = ""
replace vi_MM_matches = vi if group1>group1[_n-1] | _n==1
forvalues i =1/20 {
  replace vi_MM_matches = vi_MM_matches + " " + vi[_n+`i'] if vi_MM_matches!="" & group1[_n+`i']==group1[_n] & vi[_n+`i']!=vi[_n+`i'-1]
}
replace vi_MM_matches = trim(subinstr(subinstr(vi_MM_matches,"village","",.),"_","",.))
egen temp1 = mode(bk_MM_matches), by(group1)
egen temp2 = mode(vi_MM_matches), by(group1)
replace bk_MM_matches = temp1 if bk_MM_matches=="" 
replace vi_MM_matches = temp2 if vi_MM_matches=="" 
replace bk_MM_matches = subinstr(bk_MM_matches,"11 11","11",.)
replace bk_MM_matches = subinstr(bk_MM_matches,"11 11","11",.)
replace bk_MM_matches = subinstr(bk_MM_matches,"pca pca","pca",.)
replace bk_MM_matches = subinstr(bk_MM_matches,"pca pca","pca",.)
replace bk_MM_matches = subinstr(bk_MM_matches,"2vd11 2vd11","2vd11",.)
replace bk_MM_matches = subinstr(bk_MM_matches,"2vd11 2vd11","2vd11",.)
*replace bk_MM_matches = subinstr(bk_MM_matches,"nobk nobk","nobk",.)
*replace bk_MM_matches = subinstr(bk_MM_matches,"nobk nobk","nobk",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"conc01 vd 11 conc01 vd 11","conc01 vd 11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"conc01 vd conc01 vd","conc01 vd",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"conc01 vd conc01 vd","conc01 vd",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"11 conc01 pca 11 conc01 pca","11 conc01 pca",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"11 vd 11 vd","11 vd",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"11 pca 11 pca","11 pca",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"11 vd11 11 vd11","11 vd11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"pca pca","pca",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"11 11","11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"11 pca","pca 11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"pca vd pca vd","pca vd",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"pca vd pca vd","pca vd",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"vd vd","vd",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"vd","vd",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"pca","pca",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"conc01 pca","pca conc01",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"11 pca vd","pca vd 11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"11 vd", "vd 11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"pca pca 11 11","pca 11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"pca 11 pca 11","pca 11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"vd 11 vd 11","vd 11",.)
replace vi_MM_matches = subinstr(vi_MM_matches,"vd 11 vd 11","vd 11",.)
compress

  // step down multiple (identical) village matches, for the same (names_id, schv_id, bk)
gen vi_pca = vi=="village_pca"
egen vi_pca_max = max(vi_pca), by(names_id schv_id bk)
drop if vi_pca_max==1 & vi_pca==0
gen vi_vd = vi=="village_vd"
egen vi_vd_max = max(vi_vd), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==1 & vi_vd==0
gen vi_11 = vi=="village11"
egen vi_11_max = max(vi_11), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==0 & vi_11_max==1 & vi_11==0
gen vi_conc01 = vi=="village_conc01"
egen vi_conc01_max = max(vi_conc01), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==0 & vi_11_max==0 & vi_conc01_max==1 & vi_conc01==0
gen vi_conc11 = vi=="village_conc11"
egen vi_conc11_max = max(vi_conc11), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==0 & vi_11_max==0 & vi_conc01_max==0 & vi_conc11_max==1 & vi_conc11==0
gen vi_2vd11 = vi=="village_2vd11"
egen vi_2vd11_max = max(vi_2vd11), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==0 & vi_11_max==0 & vi_conc01_max==0 & vi_conc11_max==0 & vi_2vd11_max==1 & vi_2vd11==0

  // drop duplicates after having reshaped and kept preferred village match
drop bk vi vi_pca-vi_2vd11_max temp1 temp2
duplicates drop
duplicates r names_id schv_id
duplicates r names_id
duplicates r schv_id

  // find masala-levenshtein distance for each remaining MM_match
gen Mvillage = village_pca if regexm(vi_MM_matches,"pca")
replace Mvillage = village_vd if regexm(vi_MM_matches,"vd") & Mvillage==""
replace Mvillage = village11 if regexm(vi_MM_matches,"11") & Mvillage==""
replace Mvillage = village_conc01 if regexm(vi_MM_matches,"conc01") & Mvillage==""
replace Mvillage = village_conc11 if regexm(vi_MM_matches,"conc11") & Mvillage==""
replace Mvillage = village_vd11 if regexm(vi_MM_matches,"2vd11") & Mvillage==""
*masala_lev_dist villageS Mvillage, gen(mldist)


*Verify MM_matches with blocks, based on string distance and population, and resolve dupes
 *br names_id schv_id bk_MM_matches vi_MM_matches Mvillage villageS lev_dist if bk_MM!="nobk"

  // resolve the few names_id dupes
sort names_id schv_id
duplicates t names_id if bk_MM!="nobk", gen(dup1)
replace dup1 = 0 if dup1==.
*br names_id schv_id bk_MM_matches vi_MM_matches Mvillage villageS lev_dist if bk_MM!="nobk" & dup1>0
*drop if dup1>0  // these are dupes we want to keep, because the village names are identical and the block names have changed over time

  // resolve schv_id dupes
duplicates t schv_id if bk_MM!="nobk", gen(dup2)
replace dup2 = 0 if dup2==.
*br names_id schv_id pca01_id bk_MM_matches vi_MM_matches Mvillage villageS lev_dist if bk_MM!="nobk" & dup2>0
      // these are mostly dupes matched to a single pca01_id, so I'm keeping them

  // keep the acceptable matches
gen keep_flag = 0 if bk_MM!="nobk"	
sort lev_dist
*br names_id schv_id bk_MM_matches vi_MM_matches Mvillage villageS lev_dist blockS block_pca block11 block2_vd11 if keep_flag==0 
replace keep_flag = 1 if keep_flag==0 
     // no quibbles here, MM did a great job

  // drop any nobk matches that are now irrelevant, since we have a bk match
egen max_keep_flag1 = max(keep_flag), by(names_id)
egen max_keep_flag2 = max(keep_flag), by(schv_id)
drop if keep_flag==. & max_keep_flag1==1  // drop names_id's with pending nobk matches, because they're no longer on the market
drop if keep_flag==. & max_keep_flag2==1  // drop schv_id's with pending nobk matches, because they're no longer on the market

  // drop any nobk matches that have too idiosyncratic block pairings
*egen temp_nobk_bmatch_pca = count(names_id) if bk_MM=="nobk", by(blockS block_pca)
*egen temp_nobk_bmatch_11 = count(names_id) if bk_MM=="nobk", by(blockS block11)
*egen temp_nobk_bmatch_2vd11 = count(names_id) if bk_MM=="nobk", by(blockS block_2vd11)
*egen temp_nobk_bmatch_max = rowmax(temp_nobk_bmatch*)
*gsort -temp_nobk_bmatch_max lev_dist
*br names_id schv_id bk_MM_matches vi_MM_matches Mvillage villageS lev_dist temp_nobk_bmatch_max blockS block_pca block11 block2_vd11 if bk_MM=="nobk"
*drop if bk_MM=="nobk" & temp_nobk_bmatch_max<15
			// after looking closely through remaming MM_matches, the script appears to have done an EXCELLENT job! 
			// i am dropping matches where temp_nobk_bmatch_max < 15, which means that the schools block is paired with
			// another block (2001 PCA, 2011 PCA, 2VD11) at least 15 other times across all nobk MM matches

  // keep nobk matches only if they have a school in the VD
*replace keep_flag = 2 if keep_flag==. & (vd_edu_n_p_sch_11>0 & vd_edu_n_p_sch_11!=.) & (vd_edu_n_p_sch_01>0 & vd_edu_n_p_sch_01!=.) 
*replace keep_flag = 2 if keep_flag==. & (vd_edu_n_p_sch_11>0 & vd_edu_n_p_sch_11!=.)
*replace keep_flag = 2 if keep_flag==. & (vd_edu_n_p_sch_01>0 & vd_edu_n_p_sch_01!=.)

  // resolve remaining names_id duplicates 
*duplicates t names_id if (keep_flag==0 | keep_flag==.), gen(dup3)
*sort names_id 
*br names_id schv_id bk_MM_matches vi_MM_matches Mvillage villageS blockS lev_dist dup3 if dup3>0 & dup3!=.
*drop if dup3>0 & dup3!=.  // drop these dupes, they are only XXX of them and they have blocks that are all over the place

*Drop duplicates and prepare for appending to matched dataset
drop if keep_flag==0 | keep_flag==.
keep names_id schv_id nschools count_sch_id blockS villageS bk_MM vi_MM lev_dist
duplicates drop 
duplicates r names_id
duplicates r schv_id

*Append to matched dataset and remove from unmatched dataset
preserve
merge m:1 names_id using "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", keep(3) nogen
append using "$smerge/pca_2001_names_merges_all_temp_matched.dta"
order pca01_id names_id schv_id blockS villageS nschools count_sch_id st_code-d_vill 
compress
save "$smerge/pca_2001_names_merges_all_temp_matched.dta", replace
restore
keep names_id 
duplicates drop  
merge 1:1 names_id using "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", keep(2) nogen
save "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", replace

*Split hab census dataset into matched and unmatched villages
use "$schools/schools_ALL_for_merge.dta", clear
merge 1:m schv_id using "$smerge/pca_2001_names_merges_all_temp_matched.dta", keepusing(schv_id)
duplicates drop 
assert _merge!=2
preserve
keep if _merge==3
drop _merge
save "$schools/school_census_for_merge_temp_matched.dta", replace
restore
unique schv_id if _merge==1
merge 1:m schv_id using "$schools/schools_ALL_for_merge_all.dta", gen(m_schv9_id) keepusing(schv9_id) keep(1 3)
assert m_schv9_id==3
egen _merge_max = max(_merge), by(schv9_id)
keep if _merge==1 & _merge_max==1
drop _merge m_schv9_id _merge_max schv9_id
duplicates drop
unique schv_id
save "$schools/school_census_for_merge_temp_unmatched.dta", replace
}	
  // send remaining unmatched files to the server for a fuzzy (masala) merge (without matching block)
  // "merge_schools_fuzzy.do", Step 6	

********************************************************************************
********************************************************************************

** Step 8: Village matches, part V: Process masala matches from server (without matching blocks)
  // get masala merge results from server
{
*Drop duplicates from MMout_all, "reshape", and calculate M-L distance
use "$schools/MMout_all_nobk.dta", clear
sort  names_id schv_id bk vi
*br names_id schv_id bk vi

  // "reshape" bk and vi by hand
egen group1 = group(names_id schv_id)
sort group1 bk vi
gen bk_MM_matches = ""
replace bk_MM_matches = bk if group1>group1[_n-1] | _n==1
forvalues i =1/4 {
  replace bk_MM_matches = bk_MM_matches + " " + bk[_n+`i'] if bk_MM_matches!="" & group1[_n+`i']==group1[_n] 
}
gen vi_MM_matches = ""
replace vi_MM_matches = vi if group1>group1[_n-1] | _n==1
forvalues i =1/20 {
  replace vi_MM_matches = vi_MM_matches + " " + vi[_n+`i'] if vi_MM_matches!="" & group1[_n+`i']==group1[_n] & vi[_n+`i']!=vi[_n+`i'-1]
}
replace vi_MM_matches = trim(subinstr(subinstr(vi_MM_matches,"village","",.),"_","",.))
egen temp1 = mode(bk_MM_matches), by(group1)
egen temp2 = mode(vi_MM_matches), by(group1)
replace bk_MM_matches = temp1 if bk_MM_matches=="" 
replace vi_MM_matches = temp2 if vi_MM_matches=="" 
replace bk_MM_matches = subinstr(bk_MM_matches,"nobk nobk","nobk",.)
compress

  // step down multiple (identical) village matches, for the same (names_id, schv_id, bk)
gen vi_pca = vi=="village_pca"
egen vi_pca_max = max(vi_pca), by(names_id schv_id bk)
drop if vi_pca_max==1 & vi_pca==0
gen vi_vd = vi=="village_vd"
egen vi_vd_max = max(vi_vd), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==1 & vi_vd==0
gen vi_11 = vi=="village11"
egen vi_11_max = max(vi_11), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==0 & vi_11_max==1 & vi_11==0
gen vi_conc01 = vi=="village_conc01"
egen vi_conc01_max = max(vi_conc01), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==0 & vi_11_max==0 & vi_conc01_max==1 & vi_conc01==0
gen vi_conc11 = vi=="village_conc11"
egen vi_conc11_max = max(vi_conc11), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==0 & vi_11_max==0 & vi_conc01_max==0 & vi_conc11_max==1 & vi_conc11==0
gen vi_2vd11 = vi=="village_2vd11"
egen vi_2vd11_max = max(vi_2vd11), by(names_id schv_id bk)
drop if vi_pca_max==0 & vi_vd_max==0 & vi_11_max==0 & vi_conc01_max==0 & vi_conc11_max==0 & vi_2vd11_max==1 & vi_2vd11==0

  // drop duplicates after having reshaped and kept preferred village match
drop bk vi vi_pca-vi_2vd11_max temp1 temp2
duplicates drop
duplicates r names_id schv_id
duplicates r names_id
duplicates r schv_id

  // create unified matched village field
gen Mvillage = village_pca if regexm(vi_MM_matches,"pca")
replace Mvillage = village_vd if regexm(vi_MM_matches,"vd") & Mvillage==""
replace Mvillage = village11 if regexm(vi_MM_matches,"11") & Mvillage==""
replace Mvillage = village_conc01 if regexm(vi_MM_matches,"conc01") & Mvillage==""
replace Mvillage = village_conc11 if regexm(vi_MM_matches,"conc11") & Mvillage==""
replace Mvillage = village_vd11 if regexm(vi_MM_matches,"2vd11") & Mvillage==""

  // find string distance for block pairs
strdist blockS block_pca, gen(temp_dist_block_pca)
strdist blockS block11, gen(temp_dist_block11)
strdist blockS block2_vd11, gen(temp_dist_block2_vd11)

  // drop any nobk matches that have too idiosyncratic block pairings
sort names_id schv_id
egen temp_nobk_bmatch_pca = count(names_id) if bk_MM=="nobk", by(blockS block_pca)
egen temp_nobk_bmatch_11 = count(names_id) if bk_MM=="nobk", by(blockS block11)
egen temp_nobk_bmatch_2vd11 = count(names_id) if bk_MM=="nobk", by(blockS block2_vd11)
egen temp_nobk_bmatch_max = rowmax(temp_nobk_bmatch*)
egen temp_nobk_bmatch_dist_min = rowmin(temp_dist_block*)
egen temp_nobk_bmatch_dist_min2 = min(temp_nobk_bmatch_dist_min), by(blockS temp_nobk_bmatch_dist_min)
gsort -temp_nobk_bmatch_max temp_nobk_bmatch_dist_min2 blockS lev_dist
br names_id schv_id bk_MM_matches vi_MM_matches Mvillage villageS lev_dist temp_nobk_bmatch_max temp_nobk_bmatch_dist_min2 blockS block_pca block11 block2_vd11 if bk_MM=="nobk"
keep if temp_nobk_bmatch_max>=10 | (temp_nobk_bmatch_max>=5 & temp_nobk_bmatch_dist_min2<4) | temp_nobk_bmatch_dist_min2==1
			// after looking closely through remaming MM_matches, the script appears to have done an EXCELLENT job! 
			// i am dropping matches where temp_nobk_bmatch_max < 10, which means that the schools block is paired with
			// another block (2001 PCA, 2011 PCA, 2VD11) at least 10 other times across all nobk MM matches; 
			// OR it matches fewer times but the block names are very close!

  // keep nobk matches only if they have a school in the VD
*gen keep_flag = .
*replace keep_flag = 2 if keep_flag==. & (vd_edu_n_p_sch_11>0 & vd_edu_n_p_sch_11!=.) & (vd_edu_n_p_sch_01>0 & vd_edu_n_p_sch_01!=.) 
*replace keep_flag = 2 if keep_flag==. & (vd_edu_n_p_sch_11>0 & vd_edu_n_p_sch_11!=.)
*replace keep_flag = 2 if keep_flag==. & (vd_edu_n_p_sch_01>0 & vd_edu_n_p_sch_01!=.)

  // resolve remaining names_id duplicates 
duplicates t names_id, gen(dup3)
sort names_id 
*br names_id schv_id bk_MM_matches vi_MM_matches Mvillage villageS block* lev_dist dup3 if dup3>0 & dup3!=.
egen temp_min_lev_dist = min(lev_dist), by(names_id)
egen temp_min_block_dist = min(temp_nobk_bmatch_dist_min), by(names_id)
*drop if dup3>0 & dup3!=.  // keep these dupes, they're mostly the same school from different years I think

*Drop duplicates and prepare for appending to matched dataset
*drop if keep_flag==0 | keep_flag==.
keep names_id schv_id nschools count_sch_id blockS villageS bk_MM vi_MM lev_dist
duplicates drop 
duplicates r names_id
duplicates r schv_id

*Append to matched dataset and remove from unmatched dataset
preserve
merge m:1 names_id using "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", keep(3) nogen
append using "$smerge/pca_2001_names_merges_all_temp_matched.dta"
order pca01_id names_id schv_id blockS villageS nschools count_sch_id st_code-d_vill 
compress
save "$smerge/pca_2001_names_merges_all_temp_matched.dta", replace
restore
keep names_id 
duplicates drop  
merge 1:1 names_id using "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", keep(2) nogen
save "$smerge/pca_2001_names_merges_all_temp_unmatched.dta", replace

*Split hab census dataset into matched and unmatched villages
use "$schools/schools_ALL_for_merge.dta", clear
merge 1:m schv_id using "$smerge/pca_2001_names_merges_all_temp_matched.dta", keepusing(schv_id)
duplicates drop 
assert _merge!=2
preserve
keep if _merge==3
drop _merge
save "$schools/school_census_for_merge_temp_matched.dta", replace
restore
unique schv_id if _merge==1
merge 1:m schv_id using "$schools/schools_ALL_for_merge_all.dta", gen(m_schv9_id) keepusing(schv9_id) keep(1 3)
assert m_schv9_id==3
egen _merge_max = max(_merge), by(schv9_id)
keep if _merge==1 & _merge_max==1
drop _merge m_schv9_id _merge_max schv9_id
duplicates drop
unique schv_id
save "$schools/school_census_for_merge_temp_unmatched.dta", replace
}	

********************************************************************************
********************************************************************************

** Step 9: Village matches, part VI: Process all matches, remove dupes
{	
use "$smerge/pca_2001_names_merges_all_temp_matched.dta", clear
duplicates drop
compress
duplicates r names_id schv_id

*Resolve names_id dupes
duplicates t names_id, gen(dup1)
sort names_id
*br names_id schv_id village villageS fvillage block_pca blockS if dup1>0
count if dup1>0
*drop if dup1>0 // 1% of names_ids, and a lot of these are matches we want (variant block/village spellings in schools data)

*Resolve schv_id dupes, once and for all
duplicates t schv_id, gen(dup2)	
sort schv_id

  // flag duplicates that are already in names_id
duplicates t schv_id pca01_id, gen(dup_pca)
*br names_id pca01_id vd01_id pca11_id schv_id dup* if dup2>0 & dup2==dup_pca
gen names_collapse = ""
replace names_collapse = "pca dup" if dup2>0 & dup2==dup_pca & pca01_id!=.

  // flag duplicates where one match is to a village with VD schools and the other is not
gen vd_sch_any = (vd_edu_d_11 | vd_edu_d_01)
egen temp_vdsch_any_max = max(vd_sch_any), by(schv_id)
gen vd_sch_both = (vd_edu_d_11 & vd_edu_d_01)
egen temp_vdsch_both_max = max(vd_sch_both), by(schv_id)
unique names_id
unique pca01_id
drop if dup2>0 & names_collapse=="" & vd_sch_any<temp_vdsch_any_max
drop if dup2>0 & names_collapse=="" & vd_sch_both<temp_vdsch_both_max
unique names_id
unique pca01_id

  // merge in uncollapsed schools dataset to try resolve multiple matches of a single school with variant spellings
gen row_id = _n
duplicates t names_id, gen(dup3a)
duplicates t schv_id, gen(dup3b)
tab dup3b
gen flag_1to1 = dup3a==0 & dup3b==0
joinby schv_id using "$schools/schools_ALL_for_merge_all.dta", unmatched(master)
egen max_flag_1to1 = max(flag_1to1), by (schv9_id)
egen min_flag_1to1 = min(flag_1to1), by (schv9_id)
unique schv9_id
unique schv9_id if max_flag_1to1==1 & min_flag_1to1==0 & flag_1to1==0
drop if max_flag_1to1==1 & min_flag_1to1==0 & flag_1to1==0 & names_collapse==""
drop _merge-min_flag_1to1
duplicates drop
unique row_id
tab dup3b

	// drop if PCA01_id is missing but not missing for duplicate match
unique pca01_id
unique schv_id
egen temp_mean_pca01_id = mean(pca01_id), by(schv_id)
drop if temp_mean_pca01_id!=. & pca01_id==.

  // drop unsplittable schv_id dups, sadly
sort schv_id
*br names_id schv_id pca01_id state schv_id villageS fvillage block_pca blockS if dup2>0 & names_collapse=="" 
duplicates t schv_id, gen(dup4)
tab dup4
unique schv_id
unique pca01_id
drop if dup4>0 & names_collapse=="" // don't know what to do about these, except drop them 
unique schv_id
unique pca01_id

  // drop remaining schv_id dupes
duplicates t schv_id if names_collapse!="pca dup", gen(dup5)
drop if dup5>0 & dup5!=.
gen pca_dup = names_collapse=="pca dup"
replace villageS = fvillage if villageS=="" & fscore!=. & fmatch!=""
drop dup* temp* flag_1to1 names_collapse vd_sch_*
duplicates drop
compress
save "$smerge/pca_2001_names_merges_all_matched_processed_new.dta", replace
}

********************************************************************************
********************************************************************************

** Step 10: Construct official PCA village - school_code crosswalk
{
use "$smerge/names_for_merge.dta", clear
merge 1:m names_id using "$smerge/pca_2001_names_merges_all_matched_processed_new.dta", ///
        keepusing(blockS villageS schv_id nschools count_sch_id pca_dup row_id) nogen

* get rid of things that won't merge
drop if schv_id==.
drop if pca01_id==.

* keep only the link we need
keep pca01_id schv_id
duplicates drop
unique pca01_id
unique schv_id

* check to make sure we don't have school-village ID's matching to multiple villages
duplicates tag schv_id, gen(dupes)
assert dupes==0
drop dupes

* merge back into school-, village-spelling-specific dataset
merge 1:m schv_id using "$schools/schools_ALL_for_merge_all.dta", keep(3) keepusing(schv9_id sch_id school_code) nogen
duplicates drop
rename school_code school_codeALL

* finally, merge in schoolcode (the school identifier we actually trust)
joinby sch_id using "$schools/schoolid_schoolcode_CROSSWALK_new.dta" 
assert school_codeALL==school_code
keep pca01_id school_code schv_id schv9_id nyears
duplicates drop
unique pca01_id
unique schv_id
egen group_schvid = group(schv_id)
egen min_schvid = min(group_schvid), by(schv9_id)
egen max_schvid = max(group_schvid), by(schv9_id)
unique schv9_id
unique schv_id if min_schvid<max_schvid
unique school_code

* for school_codes with duplicate matches, keep the most common spelling
duplicates t school_code pca01_id, gen(dup_sch_code_pca01)
duplicates t school_code, gen(dup_sch_code)
unique pca01_id
unique school_code
unique school_code if dup_sch_code>0
egen max_nyears1 = max(nyears), by(school_code pca01_id)
egen min_nyears1 = min(nyears), by(school_code pca01_id)
egen max_nyears2 = max(nyears), by(school_code)
egen min_nyears2 = min(nyears), by(school_code)
drop if dup_sch_code_pca01>0 & nyears<max_nyears1
drop if dup_sch_code>0 & nyears<max_nyears2
unique pca01_id
unique school_code
unique school_code if dup_sch_code>0

* for schv9_id's that match to multiple villages, break ties by dropping least common match
*egen min_pca01 = min(pca01_id), by(schv9_id)
*egen max_pca01 = max(pca01_id), by(schv9_id)
*gen dup_pca01 = min_pca01<max_pca01
*egen nyears_pca01 = sum(nyears), by(schv9_id pca01_id)

* drop remainig school codes matched to multiple PCA 2001 villages (<0.3% of school_code matches)
duplicates t school_code, gen(dup2)
unique school_code if dup2>0
drop if dup2>0

keep pca01_id school_code
duplicates drop
compress
save "$schools/pca_schoolcode_crosswalk_new.dta", replace
}

********************************************************************************
********************************************************************************

** Step 11: Construct village-by-year-level school data (selected variables only)
{
use "$schools/pca_schoolcode_crosswalk_new.dta", clear
unique pca01_id
unique school_code
merge 1:m school_code using "$schools/school_panel_selected_vars_new.dta"
unique school_code
cap rename ac_year school_year
cap rename pincode school_pincode
unique school_code school_year
assert length(school_code)==11
assert pca01_id!=. if _merge==3
drop if _merge==2
drop _merge
unique school_code school_year
unique pca01_id school_year

* Keep variables not in the testing data
keep pca01_id school_code school_year school_pincode electricity_in_school

* Merge in testing data
rename school_code schoolcode_str
merge 1:1 schoolcode_str school_year using "$schools/dise_testscore_update_final.dta", keep(1 3)
rename schoolcode_str school_code
assert length(school_code)==11
assert pca01_id!=. if _merge==3
drop _merge
unique school_code school_year
unique pca01_id school_year

* generate school variables
gen tot_app_prev45 = prev_g45_appeared_boys + prev_g45_appeared_girls
gen tot_enr_prev45 = prev_g45_enroll_boys + prev_g45_enroll_girls
gen tot_pass_prev45 = prev_g45_passed_boys + prev_g45_passed_girls
gen tot_pass60_prev45 = prev_g45_passed60pluspct_boys + prev_g45_passed60pluspct_girls
gen tot_app_prev78 = prev_g78_appeared_boys + prev_g78_appeared_girls
gen tot_enr_prev78 = prev_g78_enroll_boys + prev_g78_enroll_girls
gen tot_pass_prev78 = prev_g78_passed_boys + prev_g78_passed_girls
gen tot_pass60_prev78 = prev_g78_passed60pluspct_boys + prev_g78_passed60pluspct_girls

replace school_year = substr(school_year, 1, 4)
destring school_year, replace

// impute previous enrollment in current year from enrollment in prior year
sort pca01_id school_code school_year
unique school_code school_year
assert r(unique) == r(N)

by pca01_id school_code: gen prev_g45_enroll_boys_imp = g4_enroll_boys[_n-1] + g5_enroll_boys[_n-1] if school_year[_n] == school_year[_n-1] + 1
by pca01_id school_code: gen prev_g45_enroll_girls_imp = g4_enroll_girls[_n-1] + g5_enroll_girls[_n-1] if school_year[_n] == school_year[_n-1] + 1
gen tot_enr_prev45_imp = prev_g45_enroll_boys_imp + prev_g45_enroll_girls_imp

by pca01_id school_code: gen prev_g78_enroll_boys_imp = g7_enroll_boys[_n-1] + g8_enroll_boys[_n-1] if school_year[_n] == school_year[_n-1] + 1
by pca01_id school_code: gen prev_g78_enroll_girls_imp = g7_enroll_girls[_n-1] + g8_enroll_girls[_n-1] if school_year[_n] == school_year[_n-1] + 1
gen tot_enr_prev78_imp = prev_g78_enroll_boys_imp + prev_g78_enroll_girls_imp

egen temp_pincode = mode(school_pincode), by(school_code)
replace school_pincode = temp_pincode if school_pincode=="" & temp_pincode!=""
drop temp*


* non-collapsed dataset for school-level regressions
preserve
* Pass fractions out of those who took the test for all, boys, and girls
// all
gen passfrac_tot_45_a = tot_pass_prev45 / tot_app_prev45
gen passfrac_tot_78_a = tot_pass_prev78 / tot_app_prev78
gen pass60frac_tot_45_a = tot_pass60_prev45 / tot_app_prev45
gen pass60frac_tot_78_a = tot_pass60_prev78 / tot_app_prev78
// girls
gen passfrac_g_45_a = prev_g45_passed_girls / prev_g45_appeared_girls
gen passfrac_g_78_a = prev_g78_passed_girls / prev_g78_appeared_girls
gen pass60frac_g_45_a = prev_g45_passed60pluspct_girls / prev_g45_appeared_girls
gen pass60frac_g_78_a = prev_g78_passed60pluspct_girls / prev_g78_appeared_girls
// boys
gen passfrac_b_45_a = prev_g45_passed_boys / prev_g45_appeared_boys
gen passfrac_b_78_a = prev_g78_passed_boys / prev_g78_appeared_boys
gen pass60frac_b_45_a = prev_g45_passed60pluspct_boys / prev_g45_appeared_boys
gen pass60frac_b_78_a = prev_g78_passed60pluspct_boys / prev_g78_appeared_boys

foreach v of varlist passfrac_tot_45_a-pass60frac_b_78_a {
	la var `v' "out of # test takers (ie # appeared)"
}

* Pass fractions out of total enrollees for all, boys, and girls
// all
gen passfrac_tot_45_e = tot_pass_prev45 / tot_enr_prev45
gen passfrac_tot_78_e = tot_pass_prev78 / tot_enr_prev78
gen pass60frac_tot_45_e = tot_pass60_prev45 / tot_enr_prev45
gen pass60frac_tot_78_e = tot_pass60_prev78 / tot_enr_prev78
// girls
gen passfrac_g_45_e = prev_g45_passed_girls / prev_g45_enroll_girls
gen passfrac_g_78_e = prev_g78_passed_girls / prev_g78_enroll_girls
gen pass60frac_g_45_e = prev_g45_passed60pluspct_girls / prev_g45_enroll_girls
gen pass60frac_g_78_e = prev_g78_passed60pluspct_girls / prev_g78_enroll_girls
// boys
gen passfrac_b_45_e = prev_g45_passed_boys / prev_g45_enroll_boys
gen passfrac_b_78_e = prev_g78_passed_boys / prev_g78_enroll_boys
gen pass60frac_b_45_e = prev_g45_passed60pluspct_boys / prev_g45_enroll_boys
gen pass60frac_b_78_e = prev_g78_passed60pluspct_boys / prev_g78_enroll_boys

foreach v of varlist passfrac_tot_45_e-pass60frac_b_78_e {
	la var `v' "out of # enrolled"
}

* Pass fractions out of total *imputed* enrollees for all, boys, and girls
// all
gen passfrac_tot_45_imp_e = tot_pass_prev45 / tot_enr_prev45_imp
gen passfrac_tot_78_imp_e = tot_pass_prev78 / tot_enr_prev78_imp
gen pass60frac_tot_45_imp_e = tot_pass60_prev45 / tot_enr_prev45_imp
gen pass60frac_tot_78_imp_e = tot_pass60_prev78 / tot_enr_prev78_imp
// girls
gen passfrac_g_45_imp_e = prev_g45_passed_girls / prev_g45_enroll_girls_imp
gen passfrac_g_78_imp_e = prev_g78_passed_girls / prev_g78_enroll_girls_imp
gen pass60frac_g_45_imp_e = prev_g45_passed60pluspct_girls / prev_g45_enroll_girls_imp
gen pass60frac_g_78_imp_e = prev_g78_passed60pluspct_girls / prev_g78_enroll_girls_imp
// boys
gen passfrac_b_45_imp_e = prev_g45_passed_boys / prev_g45_enroll_boys_imp
gen passfrac_b_78_imp_e = prev_g78_passed_boys / prev_g78_enroll_boys_imp
gen pass60frac_b_45_imp_e = prev_g45_passed60pluspct_boys / prev_g45_enroll_boys_imp
gen pass60frac_b_78_imp_e = prev_g78_passed60pluspct_boys / prev_g78_enroll_boys_imp

foreach v of varlist passfrac_tot_45_imp_e-pass60frac_b_78_imp_e {
	la var `v' "out of # enrolled (imputed from previous year's enrollment)"
}

keep tot_pass* prev_g45_pass* prev_g78_pass* passfrac* pass60frac* tot_enr* elec* g* tot_app* tot_enr* prev_g45_enroll* prev_g78_enroll* prev_g45_appeared* prev_g78_appeared* school_year pca01_id school_pincode school_code
order pca01_id school_code school_year

* Flag observations with a greater # of test takers who appeared than who are enrolled in the school
foreach g_span of numlist 45 78 {

	gen flag_g`g_span'_app_gtr_enr_boys = prev_g`g_span'_appeared_boys > prev_g`g_span'_enroll_boys
	replace flag_g`g_span'_app_gtr_enr_boys = 0 if ///
	missing(prev_g`g_span'_appeared_boys) | missing(prev_g`g_span'_enroll_boys)
	la var flag_g`g_span'_app_gtr_enr_boys "== 1 if g`g_span' # boy test takers > # boys enrolled (both non-missing, non-imputed)"
	
	gen flag_g`g_span'_app_gtr_enr_girls = prev_g`g_span'_appeared_girls > prev_g`g_span'_enroll_girls
	replace flag_g`g_span'_app_gtr_enr_girls = 0 if ///
	missing(prev_g`g_span'_appeared_girls) | missing(prev_g`g_span'_enroll_girls)
	la var flag_g`g_span'_app_gtr_enr_girls "== 1 if g`g_span' # girl test takers > # girls enrolled (both non-missing, non-imputed)"
	
	gen flag_g`g_span'_app_gtr_enr_all = tot_app_prev`g_span' > tot_enr_prev`g_span'
	replace flag_g`g_span'_app_gtr_enr_girls = 0 if ///
	missing(tot_app_prev`g_span') | missing(tot_enr_prev`g_span')
	la var flag_g`g_span'_app_gtr_enr_all "== 1 if g`g_span' # all test takers > # all enrolled (both non-missing, non-imputed)"
}

compress
save "$panel/pca_school_selected_schoollevel_panel_new.dta", replace

rename prev_g45_passed60pluspct_boys prev_g45_pass60pluspct_boys
rename prev_g78_passed60pluspct_boys prev_g78_pass60pluspct_boys
rename prev_g45_passed60pluspct_girls prev_g45_pass60pluspct_girls
rename prev_g78_passed60pluspct_girls prev_g78_pass60pluspct_girls


reshape wide /*appfrac* */ passfrac* pass60frac* tot_app* tot_enr* prev_g45_enroll* prev_g78_enroll* prev_g45_appeared* prev_g78_appeared* flag* tot_pass* prev_g45_pass* prev_g78_pass* /* prev_g45_enr* prev_g78_enr* */ ///
      elec* g*, i(pca01_id school_code school_pincode) j(school_year)
compress
save "$panel/pca_school_selected_schoollevel_WIDE_new.dta", replace	 

restore


* collapse down to the village-by-year level
gen temp = 1
egen sch_pincode = mode(school_pincode), by(pca01_id)
collapse (count) nschools=temp (sum) tot* prev* electricity_in_school g* ///
         (max) elecany=electricity_in_school, by(pca01_id school_year sch_pincode) fast

* Pass fractions out of those who took the test for all, boys, and girls
// all
gen passfrac_tot_45_a = tot_pass_prev45 / tot_app_prev45
gen passfrac_tot_78_a = tot_pass_prev78 / tot_app_prev78
gen pass60frac_tot_45_a = tot_pass60_prev45 / tot_app_prev45
gen pass60frac_tot_78_a = tot_pass60_prev78 / tot_app_prev78
// girls
gen passfrac_g_45_a = prev_g45_passed_girls / prev_g45_appeared_girls
gen passfrac_g_78_a = prev_g78_passed_girls / prev_g78_appeared_girls
gen pass60frac_g_45_a = prev_g45_passed60pluspct_girls / prev_g45_appeared_girls
gen pass60frac_g_78_a = prev_g78_passed60pluspct_girls / prev_g78_appeared_girls
// boys
gen passfrac_b_45_a = prev_g45_passed_boys / prev_g45_appeared_boys
gen passfrac_b_78_a = prev_g78_passed_boys / prev_g78_appeared_boys
gen pass60frac_b_45_a = prev_g45_passed60pluspct_boys / prev_g45_appeared_boys
gen pass60frac_b_78_a = prev_g78_passed60pluspct_boys / prev_g78_appeared_boys

foreach v of varlist passfrac_tot_45_a-pass60frac_b_78_a {
	la var `v' "out of # test takers (ie # appeared)"
}

* Pass fractions out of total enrollees for all, boys, and girls
// all
gen passfrac_tot_45_e = tot_pass_prev45 / tot_enr_prev45
gen passfrac_tot_78_e = tot_pass_prev78 / tot_enr_prev78
gen pass60frac_tot_45_e = tot_pass60_prev45 / tot_enr_prev45
gen pass60frac_tot_78_e = tot_pass60_prev78 / tot_enr_prev78
// girls
gen passfrac_g_45_e = prev_g45_passed_girls / prev_g45_enroll_girls
gen passfrac_g_78_e = prev_g78_passed_girls / prev_g78_enroll_girls
gen pass60frac_g_45_e = prev_g45_passed60pluspct_girls / prev_g45_enroll_girls
gen pass60frac_g_78_e = prev_g78_passed60pluspct_girls / prev_g78_enroll_girls
// boys
gen passfrac_b_45_e = prev_g45_passed_boys / prev_g45_enroll_boys
gen passfrac_b_78_e = prev_g78_passed_boys / prev_g78_enroll_boys
gen pass60frac_b_45_e = prev_g45_passed60pluspct_boys / prev_g45_enroll_boys
gen pass60frac_b_78_e = prev_g78_passed60pluspct_boys / prev_g78_enroll_boys

foreach v of varlist passfrac_tot_45_e-pass60frac_b_78_e {
	la var `v' "out of # enrolled"
}

* Pass fractions out of total *imputed* enrollees for all, boys, and girls
// all
gen passfrac_tot_45_imp_e = tot_pass_prev45 / tot_enr_prev45_imp
gen passfrac_tot_78_imp_e = tot_pass_prev78 / tot_enr_prev78_imp
gen pass60frac_tot_45_imp_e = tot_pass60_prev45 / tot_enr_prev45_imp
gen pass60frac_tot_78_imp_e = tot_pass60_prev78 / tot_enr_prev78_imp
// girls
gen passfrac_g_45_imp_e = prev_g45_passed_girls / prev_g45_enroll_girls_imp
gen passfrac_g_78_imp_e = prev_g78_passed_girls / prev_g78_enroll_girls_imp
gen pass60frac_g_45_imp_e = prev_g45_passed60pluspct_girls / prev_g45_enroll_girls_imp
gen pass60frac_g_78_imp_e = prev_g78_passed60pluspct_girls / prev_g78_enroll_girls_imp
// boys
gen passfrac_b_45_imp_e = prev_g45_passed_boys / prev_g45_enroll_boys_imp
gen passfrac_b_78_imp_e = prev_g78_passed_boys / prev_g78_enroll_boys_imp
gen pass60frac_b_45_imp_e = prev_g45_passed60pluspct_boys / prev_g45_enroll_boys_imp
gen pass60frac_b_78_imp_e = prev_g78_passed60pluspct_boys / prev_g78_enroll_boys_imp

foreach v of varlist passfrac_tot_45_imp_e-pass60frac_b_78_imp_e {
	la var `v' "out of # enrolled (imputed from previous year's enrollment)"
}

* Flag observations with a greater # of test takers who appeared than who are enrolled in the school
foreach g_span of numlist 45 78 {

	gen flag_g`g_span'_app_gtr_enr_boys = prev_g`g_span'_appeared_boys > prev_g`g_span'_enroll_boys
	replace flag_g`g_span'_app_gtr_enr_boys = 0 if ///
	missing(prev_g`g_span'_appeared_boys) | missing(prev_g`g_span'_enroll_boys)
	la var flag_g`g_span'_app_gtr_enr_boys "== 1 if g`g_span' # boy test takers > # boys enrolled (both non-missing, non-imputed)"
	
	gen flag_g`g_span'_app_gtr_enr_girls = prev_g`g_span'_appeared_girls > prev_g`g_span'_enroll_girls
	replace flag_g`g_span'_app_gtr_enr_girls = 0 if ///
	missing(prev_g`g_span'_appeared_girls) | missing(prev_g`g_span'_enroll_girls)
	la var flag_g`g_span'_app_gtr_enr_girls "== 1 if g`g_span' # girl test takers > # girls enrolled (both non-missing, non-imputed)"
	
	gen flag_g`g_span'_app_gtr_enr_all = tot_app_prev`g_span' > tot_enr_prev`g_span'
	replace flag_g`g_span'_app_gtr_enr_girls = 0 if ///
	missing(tot_app_prev`g_span') | missing(tot_enr_prev`g_span')
	la var flag_g`g_span'_app_gtr_enr_all "== 1 if g`g_span' # all test takers > # all enrolled (both non-missing, non-imputed)"
}

gen elec_frac = electricity_in_school / nschools

keep /*appfrac* */ passfrac* pass60frac* /*tot_enr* prev_g45_enr* prev_g78_enr* */ ///
     nschools elec_frac elecany school_year pca01_id g* sch_pincode tot_app* tot_enr* prev_g45_enroll* prev_g78_enroll* prev_g45_appeared* prev_g78_appeared* flag* tot_pass* prev_g45_pass* prev_g78_pass*
order pca01_id school_year nschools
compress
save "$panel/pca_school_selected_panel_new.dta", replace

rename prev_g45_passed60pluspct_boys prev_g45_pass60pluspct_boys
rename prev_g78_passed60pluspct_boys prev_g78_pass60pluspct_boys
rename prev_g45_passed60pluspct_girls prev_g45_pass60pluspct_girls
rename prev_g78_passed60pluspct_girls prev_g78_pass60pluspct_girls


reshape wide /* appfrac* */ passfrac* pass60frac* tot_enr* tot_app* prev_g45_enroll* prev_g78_enroll* prev_g45_appeared* prev_g78_appeared* flag* tot_pass* prev_g45_pass* prev_g78_pass* /* prev_g45_enr* prev_g78_enr* */ /// 
             nschools elec_frac elecany g*, i(pca01_id sch_pincode) j(school_year)
compress
save "$panel/pca_school_selected_WIDE_new.dta", replace

}


********************************************************************************
********************************************************************************

